home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / PowerLisp 2.01 / Supplemental Documentation / Documentation / Chapter 22. Input & Output < prev    next >
Text File  |  1995-03-28  |  249KB  |  5,306 lines

  1. Common Lisp the Language, 2nd Edition
  2. -------------------------------------------------------------------------------
  3.  
  4. 22. Input/Output
  5.  
  6. Common Lisp provides a rich set of facilities for performing input/output. All
  7. input/output operations are performed on streams of various kinds. This chapter
  8. is devoted to stream data transfer operations. Streams are discussed in chapter
  9. 21, and ways of manipulating files through streams are discussed in chapter 23.
  10.  
  11. While there is provision for reading and writing binary data, most of the I/O
  12. operations in Common Lisp read or write characters. There are simple primitives
  13. for reading and writing single characters or lines of data. The format function
  14. can perform complex formatting of output data, directed by a control string in
  15. manner similar to a Fortran FORMAT statement or a PL/I PUT EDIT statement. The
  16. most useful I/O operations, however, read and write printed representations of
  17. arbitrary Lisp objects.
  18.  
  19. -------------------------------------------------------------------------------
  20.  
  21.    *  Printed Representation of Lisp Objects
  22.         o  What the Read Function Accepts
  23.         o  Parsing of Numbers and Symbols
  24.         o  Macro Characters
  25.         o  Standard Dispatching Macro Character Syntax
  26.         o  The Readtable
  27.         o  What the Print Function Produces
  28.    *  Input Functions
  29.         o  Input from Character Streams
  30.         o  Input from Binary Streams
  31.    *  Output Functions
  32.         o  Output to Character Streams
  33.         o  Output to Binary Streams
  34.         o  Formatted Output to Character Streams
  35.    *  Querying the User
  36.  
  37. -------------------------------------------------------------------------------
  38.  
  39. 22.1. Printed Representation of Lisp Objects
  40.  
  41. Lisp objects in general are not text strings but complex data structures. They
  42. have very different properties from text strings as a consequence of their
  43. internal representation. However, to make it possible to get at and talk about
  44. Lisp objects, Lisp provides a representation of most objects in the form of
  45. printed text; this is called the printed representation, which is used for
  46. input/output purposes and in the examples throughout this book. Functions such
  47. as print take a Lisp object and send the characters of its printed
  48. representation to a stream. The collection of routines that does this is known
  49. as the (Lisp) printer. The read function takes characters from a stream,
  50. interprets them as a printed representation of a Lisp object, builds that
  51. object, and returns it; the collection of routines that does this is called the
  52. (Lisp) reader.
  53.  
  54. Ideally, one could print a Lisp object and then read the printed representation
  55. back in, and so obtain the same identical object. In practice this is difficult
  56. and for some purposes not even desirable. Instead, reading a printed
  57. representation produces an object that is (with obscure technical exceptions)
  58. equal to the originally printed object.
  59.  
  60. Most Lisp objects have more than one possible printed representation. For
  61. example, the integer twenty-seven can be written in any of these ways:
  62.  
  63. 27    27.    #o33    #x1B    #b11011    #.(* 3 3 3)    81/3
  64.  
  65. A list of two symbols A and B can be printed in many ways:
  66.  
  67.     (A B)    (a b)    (  a  b )    ( A |B|)
  68.     (| A|
  69.   B
  70.  
  71.  
  72. The last example, which is spread over three lines, may be ugly, but it is
  73. legitimate. In general, wherever whitespace is permissible in a printed
  74. representation, any number of spaces and newlines may appear.
  75.  
  76. When print produces a printed representation, it must choose arbitrarily from
  77. among many possible printed representations. It attempts to choose one that is
  78. readable. There are a number of global variables that can be used to control
  79. the actions of print, and a number of different printing functions.
  80.  
  81. This section describes in detail what is the standard printed representation
  82. for any Lisp object and also describes how read operates.
  83.  
  84. -------------------------------------------------------------------------------
  85.  
  86.    *  What the Read Function Accepts
  87.    *  Parsing of Numbers and Symbols
  88.    *  Macro Characters
  89.    *  Standard Dispatching Macro Character Syntax
  90.    *  The Readtable
  91.    *  What the Print Function Produces
  92.  
  93. -------------------------------------------------------------------------------
  94.  
  95. 22.1.1. What the Read Function Accepts
  96.  
  97. The purpose of the Lisp reader is to accept characters, interpret them as the
  98. printed representation of a Lisp object, and construct and return such an
  99. object. The reader cannot accept everything that the printer produces; for
  100. example, the printed representations of compiled code objects cannot be read
  101. in. However, the reader has many features that are not used by the output of
  102. the printer at all, such as comments, alternative representations, and
  103. convenient abbreviations for frequently used but unwieldy constructs. The
  104. reader is also parameterized in such a way that it can be used as a lexical
  105. analyzer for a more general user-written parser.
  106.  
  107. The reader is organized as a recursive-descent parser. Broadly speaking, the
  108. reader operates by reading a character from the input stream and treating it in
  109. one of three ways. Whitespace characters serve as separators but are otherwise
  110. ignored. Constituent and escape characters are accumulated to make a token,
  111. which is then interpreted as a number or symbol. Macro characters trigger the
  112. invocation of functions (possibly user-supplied) that can perform arbitrary
  113. parsing actions, including recursive invocation of the reader.
  114.  
  115. More precisely, when the reader is invoked, it reads a single character from
  116. the input stream and dispatches according to the syntactic type of that
  117. character. Every character that can appear in the input stream must be of
  118. exactly one of the following kinds: illegal, whitespace, constituent, single
  119. escape, multiple escape, or macro. Macro characters are further divided into
  120. the types terminating and non-terminating (of tokens). (Note that macro
  121. characters have nothing whatever to do with macros in their operation. There is
  122. a superficial similarity in that macros allow the user to extend the syntax of
  123. Common Lisp at the level of forms, while macro characters allow the user to
  124. extend the syntax at the level of characters.) Constituents additionally have
  125. one or more attributes, the most important of which is alphabetic; these
  126. attributes are discussed further in section 22.1.2.
  127.  
  128. The parsing of Common Lisp expressions is discussed in terms of these syntactic
  129. character types because the types of individual characters are not fixed but
  130. may be altered by the user (see set-syntax-from-char and set-macro-character).
  131. The characters of the standard character set initially have the syntactic types
  132. shown in table 22-1. Note that the brackets, braces, question mark, and
  133. exclamation point (that is, [, ], {, }, ?, and !) are normally defined to be
  134. constituents, but they are not used for any purpose in standard Common Lisp
  135. syntax and do not occur in the names of built-in Common Lisp functions or
  136. variables. These characters are explicitly reserved to the user. The primary
  137. intent is that they be used as macro characters; but a user might choose, for
  138. example, to make ! be a single escape character (as it is in Portable Standard
  139. Lisp).
  140.  
  141.  
  142.  
  143. ----------------------------------------------------------------
  144. Table 22-1: Standard Character Syntax Types
  145.  
  146. <tab> whitespace          <page> whitespace <newline> whitespace
  147. <space> whitespace        @ constituent     ` terminating macro
  148. ! constituent *           A constituent     a constituent
  149. " terminating macro       B constituent     b constituent
  150. # non-terminating macro   C constituent     c constituent
  151. $ constituent             D constituent     d constituent
  152. % constituent             E constituent     e constituent
  153. & constituent             F constituent     f constituent
  154. ' terminating macro       G constituent     g constituent
  155. ( terminating macro       H constituent     h constituent
  156. ) terminating macro       I constituent     i constituent
  157. * constituent             J constituent     j constituent
  158. + constituent             K constituent     k constituent
  159. , terminating macro       L constituent     l constituent
  160. - constituent             M constituent     m constituent
  161. . constituent             N constituent     n constituent
  162. / constituent             O constituent     o constituent
  163. 0 constituent             P constituent     p constituent
  164. 1 constituent             Q constituent     q constituent
  165. 2 constituent             R constituent     r constituent
  166. 3 constituent             S constituent     s constituent
  167. 4 constituent             T constituent     t constituent
  168. 5 constituent             U constituent     u constituent
  169. 6 constituent             V constituent     v constituent
  170. 7 constituent             W constituent     w constituent
  171. 8 constituent             X constituent     x constituent
  172. 9 constituent             Y constituent     y constituent
  173. : constituent             Z constituent     z constituent
  174. ; terminating macro       [ constituent *   { constituent *
  175. < constituent             \ single escape   | multiple escape
  176. = constituent             ] constituent *   } constituent *
  177. > constituent             ^ constituent     ~ constituent
  178. ? constituent *           _ constituent     <rubout> constituent
  179. <bkspace> constituent  <return> whitespace <linefeed> whitespace
  180.  
  181. The characters marked with an asterisk are initially constituents
  182. but are reserved to the user for use as macro characters or for
  183. any other desired purpose.
  184. ----------------------------------------------------------------
  185.  
  186. The algorithm performed by the Common Lisp reader is roughly as follows:
  187.  
  188.   1.  If at end of file, perform end-of-file processing (as specified by the
  189.      caller of the read function). Otherwise, read one character from the input
  190.      stream, call it x, and dispatch according to the syntactic type of x to
  191.      one of steps 2 to 7.
  192.  
  193.   2.  If x is an illegal character, signal an error.
  194.  
  195.   3.  If x is a whitespace character, then discard it and go back to step 1.
  196.  
  197.   4.  If x is a macro character (at this point the distinction between
  198.      terminating and non-terminating macro characters does not matter), then
  199.      execute the function associated with that character. The function may
  200.      return zero values or one value (see values).
  201.  
  202.      The macro-character function may of course read characters from the input
  203.      stream; if it does, it will see those characters following the macro
  204.      character. The function may even invoke the reader recursively. This is
  205.      how the macro character ( constructs a list: by invoking the reader
  206.      recursively to read the elements of the list.
  207.  
  208.      If one value is returned, then return that value as the result of the read
  209.      operation; the algorithm is done. If zero values are returned, then go
  210.      back to step 1.
  211.  
  212.   5.  If x is a single escape character (normally ), then read the next
  213.      character and call it y (but if at end of file, signal an error instead).
  214.      Ignore the usual syntax of y and pretend it is a constituent whose only
  215.      attribute is alphabetic.
  216.  
  217.      [old_change_begin]
  218.      (If y is a lowercase character, leave it alone; do not replace it with the
  219.      corresponding uppercase character.)
  220.      [old_change_end]
  221.  
  222.      [change_begin]
  223.      For the purposes of readtable-case, y is not replaceable.
  224.      [change_end]
  225.  
  226.      Use y to begin a token, and go to step 8.
  227.  
  228.   6.  If x is a multiple escape character (normally |), then begin a token
  229.      (initially containing no characters) and go to step 9.
  230.  
  231.   7.  If x is a constituent character, then it begins an extended token. After
  232.      the entire token is read in, it will be interpreted either as representing
  233.      a Lisp object such as a symbol or number (in which case that object is
  234.      returned as the result of the read operation), or as being of illegal
  235.      syntax (in which case an error is signaled).
  236.  
  237.      [old_change_begin]
  238.      If x is a lowercase character, replace it with the corresponding uppercase
  239.      character.
  240.      [old_change_end]
  241.  
  242.      [change_begin]
  243.      X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to introduce
  244.      readtable-case. Consequently, the preceding sentence should be ignored.
  245.      The case of x should not be altered; instead, x should be regarded as
  246.      replaceable.
  247.      [change_end]
  248.  
  249.      Use x to begin a token, and go on to step 8.
  250.  
  251.   8.  (At this point a token is being accumulated, and an even number of
  252.      multiple escape characters have been encountered.) If at end of file, go
  253.      to step 10. Otherwise, read a character (call it y), and perform one of
  254.      the following actions according to its syntactic type:
  255.  
  256.         o  If y is a constituent or non-terminating macro, then do the
  257.           following.
  258.  
  259.           [old_change_begin]
  260.           If y is a lowercase character, replace it with the corresponding
  261.           uppercase character.
  262.           [old_change_end]
  263.  
  264.           [change_begin]
  265.           X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to introduce
  266.           readtable-case. Consequently, the preceding sentence should be
  267.           ignored. The case of y should not be altered; instead, y should be
  268.           regarded as replaceable.
  269.  
  270.           Append y to the token being built, and repeat step 8.
  271.           [change_end]
  272.  
  273.         o  If y is a single escape character, then read the next character and
  274.           call it z (but if at end of file, signal an error instead). Ignore
  275.           the usual syntax of z and pretend it is a constituent whose only
  276.           attribute is alphabetic.
  277.  
  278.           [old_change_begin]
  279.           (If z is a lowercase character, leave it alone; do not replace it
  280.           with the corresponding uppercase character.)
  281.           [old_change_end]
  282.  
  283.           [change_begin]
  284.           For the purposes of readtable-case, z is not replaceable.
  285.           [change_end]
  286.  
  287.           Append z to the token being built, and repeat step 8.
  288.  
  289.         o  If y is a multiple escape character, then go to step 9.
  290.  
  291.         o  If y is an illegal character, signal an error.
  292.  
  293.         o  If y is a terminating macro character, it terminates the token.
  294.           First ``unread'' the character y (see unread-char), then go to step
  295.           10.
  296.  
  297.         o  If y is a whitespace character, it terminates the token. First
  298.           ``unread'' y if appropriate (see read-preserving-whitespace), then go
  299.           to step 10.
  300.  
  301.   9.  (At this point a token is being accumulated, and an odd number of
  302.      multiple escape characters have been encountered.) If at end of file,
  303.      signal an error. Otherwise, read a character (call it y), and perform one
  304.      of the following actions according to its syntactic type:
  305.  
  306.         o  If y is a constituent, macro, or whitespace character, then ignore
  307.           the usual syntax of that character and pretend it is a constituent
  308.           whose only attribute is alphabetic.
  309.  
  310.           [old_change_begin]
  311.           (If y is a lowercase character, leave it alone; do not replace it
  312.           with the corresponding uppercase character.)
  313.           [old_change_end]
  314.  
  315.           [change_begin]
  316.           For the purposes of readtable-case, y is not replaceable.
  317.           [change_end]
  318.  
  319.           Append y to the token being built, and repeat step 9.
  320.  
  321.         o  If y is a single escape character, then read the next character and
  322.           call it z (but if at end of file, signal an error instead). Ignore
  323.           the usual syntax of z and pretend it is a constituent whose only
  324.           attribute is alphabetic.
  325.  
  326.           [old_change_begin]
  327.           (If z is a lowercase character, leave it alone; do not replace it
  328.           with the corresponding uppercase character.)
  329.           [old_change_end]
  330.  
  331.           [change_begin]
  332.           For the purposes of readtable-case, z is not replaceable.
  333.           [change_end]
  334.  
  335.           Append z to the token being built, and repeat step 9.
  336.  
  337.         o  If y is a multiple escape character, then go to step 8.
  338.  
  339.         o  If y is an illegal character, signal an error.
  340.  
  341.  10.  An entire token has been accumulated.
  342.  
  343.      [change_begin]
  344.      X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to introduce
  345.      readtable-case. If the accumulated token is to be interpreted as a symbol,
  346.      any case conversion of replaceable characters should be performed at this
  347.      point according to the value of the readtable-case slot of the current
  348.      readtable (the value of *readtable*).
  349.      [change_end]
  350.  
  351.      Interpret the token as representing a Lisp object and return that object
  352.      as the result of the read operation, or signal an error if the token is
  353.      not of legal syntax.
  354.  
  355.      [change_begin]
  356.      X3J13 voted in March 1989 (CHARACTER-PROPOSAL)   to specify that
  357.      implementation-defined attributes may be removed from the characters of a
  358.      symbol token when constructing the print name. It is
  359.      implementation-dependent which attributes are removed.
  360.      [change_end]
  361.  
  362. As a rule, a single escape character never stands for itself but always serves
  363. to cause the following character to be treated as a simple alphabetic
  364. character. A single escape character can be included in a token only if
  365. preceded by another single escape character.
  366.  
  367. A multiple escape character also never stands for itself. The characters
  368. between a pair of multiple escape characters are all treated as simple
  369. alphabetic characters, except that single escape and multiple escape characters
  370. must nevertheless be preceded by a single escape character to be included.
  371.  
  372. -------------------------------------------------------------------------------
  373. Compatibility note: In MacLisp, the | character is implemented as a macro
  374. character that reads characters up to the next unescaped | and then makes a
  375. token; no characters are ever read beyond the second | of a matching pair. In
  376. Common Lisp, the second | does not terminate the token being read but merely
  377. reverts to the ordinary (rather than multiple-escape) mode of token
  378. accumulation. This results in some differences in the way certain character
  379. sequences are interpreted. For example, the sequence |foo||bar| would be read
  380. in MacLisp as two distinct tokens, |foo| and |bar|, whereas in Common Lisp it
  381. would be treated as a single token equivalent to |foobar|. The sequence
  382. |foo|bar|baz| would be read in MacLisp as three distinct tokens, |foo|, bar,
  383. and |baz|, whereas in Common Lisp it would be treated as a single token
  384. equivalent to |fooBARbaz|; note that the middle three lowercase letters are
  385. converted to uppercase letters as they do not fall within a matching pair of
  386. vertical bars.
  387.  
  388. One reason for the different treatment of | in Common Lisp lies in the syntax
  389. for package-qualified symbol names. A sequence such as |foo:bar| ought to be
  390. interpreted as a symbol whose name is foo:bar; the colon should be treated as a
  391. simple alphabetic character because it lies within a pair of vertical bars. The
  392. symbol |bar| within the package |foo| can be notated not as |foo:bar| but as
  393. |foo|:|bar|; the colon can serve as a package marker because it falls outside
  394. the vertical bars, and yet the notation is treated as a single token thanks to
  395. the new rules adopted in Common Lisp.
  396.  
  397. In MacLisp, the parentheses are treated as additional character types. In
  398. Common Lisp they are simply macro characters, as described in section 22.1.3.
  399.  
  400. What MacLisp calls ``single character objects'' (tokens of type single) are not
  401. provided for explicitly in Common Lisp. They can be viewed as simply a kind of
  402. macro character. That is, the effect of
  403.  
  404. (setsyntax '$ 'single nil)
  405. (setsyntax '% 'single nil)
  406.  
  407. in MacLisp can be achieved in Common Lisp by
  408.  
  409. (defun single-macro-character (stream char)
  410.   (declare (ignore stream))
  411.   (intern (string char)))
  412. (set-macro-character '$ #'single-macro-character)
  413. (set-macro-character '% #'single-macro-character)
  414.  
  415. -------------------------------------------------------------------------------
  416.  
  417. -------------------------------------------------------------------------------
  418.  
  419. 22.1.2. Parsing of Numbers and Symbols
  420.  
  421. When an extended token is read, it is interpreted as a number or symbol. In
  422. general, the token is interpreted as a number if it satisfies the syntax for
  423. numbers specified in table 22-2; this is discussed in more detail below.
  424.  
  425. The characters of the extended token may serve various syntactic functions as
  426. shown in table 22-3, but it must be remembered that any character included in a
  427. token under the control of an escape character is treated as alphabetic rather
  428. than according to the attributes shown in the table. One consequence of this
  429. rule is that a whitespace, macro, or escape character will always be treated as
  430. alphabetic within an extended token because such a character cannot be included
  431. in an extended token except under the control of an escape character.
  432.  
  433. To allow for extensions to the syntax of numbers, a syntax for potential
  434. numbers is defined in Common Lisp that is more general than the actual syntax
  435. for numbers. Any token that is not a potential number and does not consist
  436. entirely of dots will always be taken to be a symbol, now and in the future;
  437. programs may rely on this fact. Any token that is a potential number but does
  438. not fit the actual number syntax defined below is a reserved token and has an
  439. implementation-dependent interpretation; an implementation may signal an error,
  440. quietly treat the token as a symbol, or take some other action. Programmers
  441. should avoid the use of such reserved tokens. (A symbol whose name looks like a
  442. reserved token can always be written using one or more escape characters.)
  443.  
  444. [change_begin]
  445. Just as bignum is the standard term used by Lisp implementors for very large
  446. integers, and flonum (rhymes with ``low hum'') refers to a floating-point
  447. number, the term potnum has been used widely as an abbreviation for ``potential
  448. number.'' ``Potnum'' rhymes with ``hot rum.''
  449. [change_end]
  450.  
  451. ----------------------------------------------------------------
  452. Table 22-2: Actual Syntax of Numbers
  453.  
  454. number ::= integer | ratio | floating-point-number
  455. integer ::= [sign] {digit}+ [decimal-point]
  456. ratio ::= [sign] {digit}+ / {digit}+
  457. floating-point-number ::= [sign] {digit}* decimal-point {digit}+ [exponent]
  458.                        | [sign] {digit}+ [decimal-point {digit}*] exponent
  459. sign ::= + | -
  460. decimal-point ::= .
  461. digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  462. exponent ::= exponent-marker [sign] {digit}+
  463. exponent-marker ::= e | s | f | d | l | E | S | F | D | L
  464. ----------------------------------------------------------------
  465.  
  466.  
  467.  
  468. ----------------------------------------------------------------
  469. Table 22-3: Standard Constituent Character Attributes
  470.  
  471. ! alphabetic       <page>   illegal          <backspace>   illegal
  472. " alphabetic *     <return> illegal *        <tab>         illegal *
  473. # alphabetic *     <space>  illegal *        <newline>     illegal *
  474. $ alphabetic       <rubout> illegal          <linefeed>    illegal *
  475. % alphabetic       .        alphabetic, dot, decimal point
  476. & alphabetic       +        alphabetic, plus sign
  477. ' alphabetic *     -        alphabetic, minus sign
  478. ( alphabetic *     *        alphabetic
  479. ) alphabetic *     /        alphabetic, ratio marker
  480. , alphabetic *     @        alphabetic
  481. 0 alphadigit       A, a     alphadigit
  482. 1 alphadigit       B, b     alphadigit
  483. 2 alphadigit       C, c     alphadigit
  484. 3 alphadigit       D, d     alphadigit, double-float exponent marker
  485. 4 alphadigit       E, e     alphadigit, float exponent marker
  486. 5 alphadigit       F, f     alphadigit, single-float exponent marker
  487. 6 alphadigit       G, g     alphadigit
  488. 7 alphadigit       H, h     alphadigit
  489. 8 alphadigit       I, i     alphadigit
  490. 9 alphadigit       J, j     alphadigit
  491. : package marker   K, k     alphadigit
  492. ; alphabetic *     L, l     alphadigit, long-float exponent marker
  493. < alphabetic       M, m     alphadigit
  494. = alphabetic       N, n     alphadigit
  495. > alphabetic       O, o     alphadigit
  496. ? alphabetic       P, p     alphadigit
  497. [ alphabetic       Q, q     alphadigit
  498. \ alphabetic *     R, r     alphadigit
  499. ] alphabetic       S, s     alphadigit, short-float exponent marker
  500. ^ alphabetic       T, t     alphadigit
  501. _ alphabetic       U, u     alphadigit
  502. ` alphabetic *     V, v     alphadigit
  503. { alphabetic       W, w     alphadigit
  504. | alphabetic *     X, x     alphadigit
  505. } alphabetic       Y, y     alphadigit
  506. ~ alphabetic       Z, z     alphadigit
  507.  
  508. ----------------------------------------------------------------
  509.  
  510. A token is a potential number if it satisfies the following requirements:
  511.  
  512.    *  It consists entirely of digits, signs (+ or -), ratio markers (/),
  513.      decimal points (.), extension characters (^ or _), and number markers. (A
  514.      number marker is a letter. Whether a letter may be treated as a number
  515.      marker depends on context, but no letter that is adjacent to another
  516.      letter may ever be treated as a number marker. Floating-point exponent
  517.      markers are instances of number markers.)
  518.  
  519.    *  It contains at least one digit. (Letters may be considered to be digits,
  520.      depending on the value of *read-base*, but only in tokens containing no
  521.      decimal points.)
  522.  
  523.    *  It begins with a digit, sign, decimal point, or extension character.
  524.  
  525.    *  It does not end with a sign.
  526.  
  527. As examples, the following tokens are potential numbers, but they are not
  528. actually numbers as defined below, and so are reserved tokens. (They do
  529. indicate some interesting possibilities for future extensions.)
  530.  
  531. 1b5000       777777q      1.7J       -3/4+6.7J    12/25/83
  532. 27^19        3^4/5        6//7       3.1.2.6      ^-43^
  533. 3.141_592_653_589_793_238_4           -3.7+2.6i-6.17j+19.6k
  534.  
  535. The following tokens are not potential numbers but are always treated as
  536. symbols:
  537.  
  538. /            /5           +            1+           1-
  539. foo+         ab.cd        _            ^            ^/-
  540.  
  541. The following tokens are potential numbers if the value of *read-base* is 16
  542. (an abnormal situation), but they are always treated as symbols if the value of
  543. *read-base* is 10 (the usual value):
  544.  
  545. bad-face        25-dec-83       a/b     fad_cafe        f^
  546.  
  547. It is possible for there to be an ambiguity as to whether a letter should be
  548. treated as a digit or as a number marker. In such a case, the letter is always
  549. treated as a digit rather than as a number marker.
  550.  
  551. Note that the printed representation for a potential number may not contain any
  552. escape characters. An escape character robs the following character of all
  553. syntactic qualities, forcing it to be strictly alphabetic and therefore
  554. unsuitable for use in a potential number. For example, all of the following
  555. representations are interpreted as symbols, not numbers:
  556.  
  557. \256   25\64   1.0\E6   |100|   3\.14159   |3/4|   3\/4   5||
  558.  
  559. In each case, removing the escape character(s) would allow the token to be
  560. treated as a number.
  561.  
  562. If a potential number can in fact be interpreted as a number according to the
  563. BNF syntax in table 22-2, then a number object of the appropriate type is
  564. constructed and returned. It should be noted that in a given implementation it
  565. may be that not all tokens conforming to the actual syntax for numbers can
  566. actually be converted into number objects. For example, specifying too large or
  567. too small an exponent for a floating-point number may make the number
  568. impossible to represent in the implementation. Similarly, a ratio with
  569. denominator zero (such as -35/000) cannot be represented in any implementation.
  570. In any such circumstance where a token with the syntax of a number cannot be
  571. converted to an internal number object, an error is signaled. (On the other
  572. hand, an error must not be signaled for specifying too many significant digits
  573. for a floating-point number; an appropriately truncated or rounded value should
  574. be produced.)
  575.  
  576. There is an omission in the syntax of numbers as described in table 22-2, in
  577. that the syntax does not account for the possible use of letters as digits. The
  578. radix used for reading integers and ratios is normally decimal. However, this
  579. radix is actually determined by the value of the variable *read-base*, whose
  580. initial value is 10. *read-base* may take on any integral value between 2 and
  581. 36; let this value be n. Then a token x is interpreted as an integer or ratio
  582. in base n if it could be properly so interpreted in the syntax #nRx (see
  583. section 22.1.4). So, for example, if the value of *read-base* is 16, then the
  584. printed representation
  585.  
  586. (a small face in a bad place)
  587.  
  588. would be interpreted as if the following representation had been read with
  589. *read-base* set to 10:
  590.  
  591. (10 small 64206 in 10 2989 place)
  592.  
  593. because four of the seven tokens in the list can be interpreted as hexadecimal
  594. numbers. This facility is intended to be used in reading files of data that for
  595. some reason contain numbers not in decimal radix; it may also be used for
  596. reading programs written in Lisp dialects (such as MacLisp) whose default
  597. number radix is not decimal. Non-decimal constants in Common Lisp programs or
  598. portable Common Lisp data files should be written using #O, #X, #B, or #nR
  599. syntax.
  600.  
  601. When *read-base* has a value greater than 10, an ambiguity is introduced into
  602. the actual syntax for numbers because a letter can serve as either a digit or
  603. an exponent marker; a simple example is 1E0 when the value of *read-base* is
  604. 16. The ambiguity is resolved in accordance with the general principle that
  605. interpretation as a digit is preferred to interpretation as a number marker.
  606. The consequence in this case is that if a token can be interpreted as either an
  607. integer or a floating-point number, then it is taken to be an integer.
  608.  
  609. If a token consists solely of dots (with no escape characters), then an error
  610. is signaled, except in one circumstance: if the token is a single dot and
  611. occurs in a situation appropriate to ``dotted list'' syntax, then it is
  612. accepted as a part of such syntax. Signaling an error catches not only
  613. misplaced dots in dotted list syntax but also lists that were truncated by
  614. *print-length* cutoff, because such lists end with a three-dot sequence (...).
  615. Examples:
  616.  
  617. (a . b)         ;A dotted pair of a and b
  618. (a.b)           ;A list of one element, the symbol named a.b
  619. (a. b)          ;A list of two elements a. and b
  620. (a .b)          ;A list of two elements a and .b
  621. (a  . b)        ;A list of three elements a, ., and b
  622. (a |.| b)       ;A list of three elements a, ., and b
  623. (a  ... b)      ;A list of three elements a, ..., and b
  624. (a |...| b)     ;A list of three elements a, ..., and b
  625. (a b . c)       ;A dotted list of a and b with c at the end
  626. .iot            ;The symbol whose name is .iot
  627. (. b)           ;Illegal; an error is signaled
  628. (a .)           ;Illegal; an error is signaled
  629. (a .. b)        ;Illegal; an error is signaled
  630. (a . . b)       ;Illegal; an error is signaled
  631. (a b c ...)     ;Illegal; an error is signaled
  632.  
  633. In all other cases, the token is construed to be the name of a symbol. If there
  634. are any package markers (colons) in the token, they divide the token into
  635. pieces used to control the lookup and creation of the symbol.
  636.  
  637. [old_change_begin]
  638. If there is a single package marker, and it occurs at the beginning of the
  639. token, then the token is interpreted as a keyword, that is, a symbol in the
  640. keyword package. The part of the token after the package marker must not have
  641. the syntax of a number.
  642.  
  643. If there is a single package marker not at the beginning or end of the token,
  644. then it divides the token into two parts. The first part specifies a package;
  645. the second part is the name of an external symbol available in that package.
  646. Neither of the two parts may have the syntax of a number.
  647.  
  648. If there are two adjacent package markers not at the beginning or end of the
  649. token, then they divide the token into two parts. The first part specifies a
  650. package; the second part is the name of a symbol within that package (possibly
  651. an internal symbol). Neither of the two parts may have the syntax of a number.
  652. [old_change_end]
  653.  
  654. [change_begin]
  655. X3J13 voted in March 1988 (COLON-NUMBER)   to clarify that, in the situations
  656. described in the preceding three paragraphs, the restriction on the syntax of
  657. the parts should be strengthened: none of the parts may have the syntax of even
  658. a potential number. Tokens such as :3600, :1/2, and editor:3.14159 were already
  659. ruled out; this clarification further declares that such tokens as :2^ 3,
  660. compiler:1.7J, and Christmas:12/25/83 are also in error and therefore should
  661. not be used in portable programs. Implementations may differ in their treatment
  662. of such package-marked potential numbers.
  663. [change_end]
  664.  
  665. If a symbol token contains no package markers, then the entire token is the
  666. name of the symbol. The symbol is looked up in the default package, which is
  667. the value of the variable *package*.
  668.  
  669. All other patterns of package markers, including the cases where there are more
  670. than two package markers or where a package marker appears at the end of the
  671. token, at present do not mean anything in Common Lisp (see chapter 11). It is
  672. therefore currently an error to use such patterns in a Common Lisp program. The
  673. valid patterns for tokens may be summarized as follows:
  674.  
  675. nnnnn            a number
  676. xxxxx            a symbol in the current package
  677. :xxxxx          a symbol in the keyword package
  678. ppppp:xxxxx     an external symbol in the ppppp package
  679. ppppp::xxxxx    a (possibly internal) symbol in the ppppp package
  680.  
  681. where nnnnn has the syntax of a number, and xxxxx and ppppp do not have the
  682. syntax of a number.
  683.  
  684. [change_begin]
  685. In accordance with the X3J13 decision noted above (COLON-NUMBER)   , xxxxx and
  686. ppppp may not have the syntax of even a potential number.
  687. [change_end]
  688.  
  689. [Variable]
  690. *read-base*
  691.  
  692. The value of *read-base* controls the interpretation of tokens by read as being
  693. integers or ratios. Its value is the radix in which integers and ratios are to
  694. be read; the value may be any integer from 2 to 36 (inclusive) and is normally
  695. 10 (decimal radix). Its value affects only the reading of integers and ratios.
  696. In particular, floating-point numbers are always read in decimal radix. The
  697. value of *read-base* does not affect the radix for rational numbers whose radix
  698. is explicitly indicated by #O, #X, #B, or #nR syntax or by a trailing decimal
  699. point.
  700.  
  701. Care should be taken when setting *read-base* to a value larger than 10,
  702. because tokens that would normally be interpreted as symbols may be interpreted
  703. as numbers instead. For example, with *read-base* set to 16 (hexadecimal
  704. radix), variables with names such as a, b, f, bad, and face will be treated by
  705. the reader as numbers (with decimal values 10, 11, 15, 2989, and 64206,
  706. respectively). The ability to alter the input radix is provided in Common Lisp
  707. primarily for the purpose of reading data files in special formats, rather than
  708. for the purpose of altering the default radix in which to read programs. The
  709. user is strongly encouraged to use #O, #X, #B, or #nR syntax when notating
  710. non-decimal constants in programs.
  711.  
  712. -------------------------------------------------------------------------------
  713. Compatibility note: This variable corresponds to the variable called ibase in
  714. MacLisp and to the function called radix in Interlisp.
  715. -------------------------------------------------------------------------------
  716.  
  717. [Variable]
  718. *read-suppress*
  719.  
  720. When the value of *read-suppress* is nil, the Lisp reader operates normally.
  721. When it is not nil, then most of the interesting operations of the reader are
  722. suppressed; input characters are parsed, but much of what is read is not
  723. interpreted.
  724.  
  725. The primary purpose of *read-suppress* is to support the operation of the
  726. read-time conditional constructs #+ and #- (see section 22.1.4). It is
  727. important for these constructs to be able to skip over the printed
  728. representation of a Lisp expression despite the possibility that the syntax of
  729. the skipped expression may not be entirely legal for the current
  730. implementation; this is because a primary application of #+ and #- is to allow
  731. the same program to be shared among several Lisp implementations despite small
  732. incompatibilities of syntax.
  733.  
  734. A non-nil value of *read-suppress* has the following specific effects on the
  735. Common Lisp reader:
  736.  
  737.    *  All extended tokens are completely uninterpreted. It matters not whether
  738.      the token looks like a number, much less like a valid number; the pattern
  739.      of package markers also does not matter. An extended token is simply
  740.      discarded and treated as if it were nil; that is, reading an extended
  741.      token when *read-suppress* is non-nil simply returns nil. (One consequence
  742.      of this is that the error concerning improper dotted-list syntax will not
  743.      be signaled.)
  744.  
  745.    *  Any standard # macro-character construction that requires, permits, or
  746.      disallows an infix numerical argument, such as #nR, will not enforce any
  747.      constraint on the presence, absence, or value of such an argument.
  748.  
  749.    *  The #\ construction always produces the value nil. It will not signal an
  750.      error even if an unknown character name is seen.
  751.  
  752.    *  Each of the #B, #O, #X, and #R constructions always scans over a
  753.      following token and produces the value nil. It will not signal an error
  754.      even if the token does not have the syntax of a rational number.
  755.  
  756.    *  The #* construction always scans over a following token and produces the
  757.      value nil. It will not signal an error even if the token does not consist
  758.      solely of the characters 0 and 1.
  759.  
  760. [old_change_begin]
  761.  
  762.    *  Each of the #. and #, constructions reads the following form (in
  763.      suppressed mode, of course) but does not evaluate it. The form is
  764.      discarded and nil is produced.
  765.  
  766. [old_change_end]
  767.  
  768. [change_begin]
  769.  
  770.      X3J13 voted in January 1989 (SHARP-COMMA-CONFUSION)   to remove #, from
  771.      the language.
  772.  
  773. [change_end]
  774.  
  775.    *  Each of the #A, #S, and #: constructions reads the following form (in
  776.      suppressed mode, of course) but does not interpret it in any way; it need
  777.      not even be a list in the case of #S, or a symbol in the case of #:. The
  778.      form is discarded and nil is produced.
  779.  
  780.    *  The #= construction is totally ignored. It does not read a following
  781.      form. It produces no object, but is treated as whitespace.
  782.  
  783.    *  The ## construction always produces nil.
  784.  
  785. Note that, no matter what the value of *read-suppress*, parentheses still
  786. continue to delimit (and construct) lists; the #( construction continues to
  787. delimit vectors; and comments, strings, and the quote and backquote
  788. constructions continue to be interpreted properly. Furthermore, such situations
  789. as '), #<, #), and #space continue to signal errors.
  790.  
  791. In some cases, it may be appropriate for a user-written macro-character
  792. definition to check the value of *read-suppress* and to avoid certain
  793. computations or side effects if its value is not nil.
  794.  
  795. [change_begin]
  796.  
  797. [Variable]
  798. *read-eval*
  799.  
  800. X3J13 voted in June 1989 (DATA-IO)   to add a new reader control variable,
  801. *read-eval*, whose default value is t. If *read-eval* is false, the #. reader
  802. macro signals an error.
  803.  
  804. Printing is also affected. If *read-eval* is false and *print-readably* is
  805. true, any print-object method that would otherwise output a #. reader macro
  806. must either output something different or signal an error of type
  807. print-not-readable.
  808.  
  809. Binding *read-eval* to nil is useful when reading data that came from an
  810. untrusted source, such as a network or a user-supplied data file; it prevents
  811. the #. reader macro from being exploited as a ``Trojan horse'' to cause
  812. arbitrary forms to be evaluated.
  813. [change_end]
  814.  
  815. -------------------------------------------------------------------------------
  816.  
  817. 22.1.3. Macro Characters
  818.  
  819. If the reader encounters a macro character, then the function associated with
  820. that macro character is invoked and may produce an object to be returned. This
  821. function may read following characters in the stream in whatever syntax it
  822. likes (it may even call read recursively) and return the object represented by
  823. that syntax. Macro characters may or may not be recognized, of course, when
  824. read as part of other special syntaxes (such as for strings).
  825.  
  826. The reader is therefore organized into two parts: the basic dispatch loop,
  827. which also distinguishes symbols and numbers, and the collection of macro
  828. characters. Any character can be reprogrammed as a macro character; this is a
  829. means by which the reader can be extended. The macro characters normally
  830. defined are as follows:
  831.  
  832. (    The left-parenthesis character initiates reading of a pair or list. The
  833.      function read is called recursively to read successive objects until a
  834.      right parenthesis is found to be next in the input stream. A list of the
  835.      objects read is returned. Thus the input sequence
  836.  
  837.      (a b c)
  838.  
  839.      is read as a list of three objects (the symbols a, b, and c). The right
  840.      parenthesis need not immediately follow the printed representation of the
  841.      last object; whitespace characters and comments may precede it. This can
  842.      be useful for putting one object on each line and making it easy to add
  843.      new objects:
  844.  
  845.      (defun traffic-light (color)
  846.        (case color
  847.          (green)
  848.          (red (stop))
  849.          (amber (accelerate))     ;Insert more colors after this line
  850.          ))
  851.  
  852.      It may be that no objects precede the right parenthesis, as in () or ( );
  853.      this reads as a list of zero objects (the empty list).
  854.  
  855.      If a token that is just a dot, not preceded by an escape character, is
  856.      read after some object, then exactly one more object must follow the dot,
  857.      possibly followed by whitespace, followed by the right parenthesis:
  858.  
  859.      (a b c . d)
  860.  
  861.      This means that the cdr of the last pair in the list is not nil, but
  862.      rather the object whose representation followed the dot. The above example
  863.      might have been the result of evaluating
  864.  
  865.      (cons 'a (cons 'b (cons 'c 'd))) => (a b c . d)
  866.  
  867.      Similarly, we have
  868.  
  869.      (cons 'znets 'wolq-zorbitan) => (znets . wolq-zorbitan)
  870.  
  871.      It is permissible for the object following the dot to be a list:
  872.  
  873.      (a b c d . (e f . (g)))
  874.  
  875.      is the same as
  876.  
  877.      (a b c d e f g)
  878.  
  879.      but a list following a dot is a non-standard form that print will never
  880.      produce.
  881.  
  882. )    The right-parenthesis character is part of various constructs (such as the
  883.      syntax for lists) using the left-parenthesis character and is invalid
  884.      except when used in such a construct.
  885.  
  886. '    The single-quote (accent acute) character provides an abbreviation to make
  887.      it easier to put constants in programs. The form 'foo reads the same as
  888.      (quote foo): a list of the symbol quote and foo.
  889.  
  890. ;    Semicolon is used to write comments.     The semicolon and all characters
  891.      up to and including the next newline are ignored. Thus a comment can be
  892.      put at the end of any line without affecting the reader. (A comment will
  893.      terminate a token, but a newline would terminate the token anyway.)
  894.  
  895. [change_begin]
  896.  
  897.      There is no functional difference between using one semicolon and using
  898.      more than one, but the conventions shown here are in common use.
  899.  
  900. [change_end]
  901.  
  902.      ;;;; COMMENT-EXAMPLE function.
  903.      ;;; This function is useless except to demonstrate comments.
  904.      ;;; (Actually, this example is much too cluttered with them.)
  905.  
  906.      (defun comment-example (x y)      ;X is anything; Y is an a-list.
  907.        (cond ((listp x) x)             ;If X is a list, use that.
  908.              ;; X is now not a list.  There are two other cases.
  909.              ((symbolp x)
  910.               ;; Look up a symbol in the a-list.
  911.               (cdr (assoc x y)))       ;Remember, (cdr nil) is nil.
  912.              ;; Do this when all else fails:
  913.              (t (cons x                ;Add x to a default list.
  914.                       '((lisp t)       ;LISP is okay.
  915.                         (fortran nil)  ;FORTRAN is not.
  916.                         (pl/i -500)    ;Note that you can put comments in
  917.                         (ada .001)     ; "data" as well as in "programs".
  918.                         ;; COBOL??
  919.                         (teco -1.0e9))))))
  920.  
  921.      In this example, comments may begin with one to four semicolons.
  922.  
  923.         o  Single-semicolon comments are all aligned to the same column at the
  924.           right; usually each comment concerns only the code it is next to.
  925.           Occasionally a comment is long enough to occupy two or three lines;
  926.           in this case, it is conventional to indent the continued lines of the
  927.           comment one space (after the semicolon).
  928.  
  929.         o  Double-semicolon comments are aligned to the level of indentation of
  930.           the code. A space conventionally follows the two semicolons. Such
  931.           comments usually describe the state of the program at that point or
  932.           the code section that follows the comment.
  933.  
  934.         o  Triple-semicolon comments are aligned to the left margin. They
  935.           usually document whole programs or large code blocks.
  936.  
  937.         o  Quadruple-semicolon comments usually indicate titles of whole
  938.           programs or large code blocks.
  939.  
  940. -------------------------------------------------------------------------------
  941. Compatibility note: These conventions arose among users of MacLisp and have
  942. been found to be very useful. The conventions are conveniently exploited by
  943. certain software tools, such as the EMACS editor and the ATSIGN listing program
  944. developed at MIT.
  945.  
  946. [change_begin]
  947. The ATSIGN listing program, alas, is no longer in use, but EMACS is widely
  948. available, especially the GNU EMACS implementation, which is available from the
  949. Free Software Foundation, 675 Massachusetts Avenue, Cambridge, Massachusetts
  950. 02139. Remember, GNU's Not UNIX.
  951. [change_end]
  952. -------------------------------------------------------------------------------
  953.  
  954. "    The double quote character begins the printed representation of a string.
  955.      Successive characters are read from the input stream and accumulated until
  956.      another double quote is encountered. An exception to this occurs if a
  957.      single escape character is seen; the escape character is discarded, the
  958.      next character is accumulated, and accumulation continues. When a matching
  959.      double quote is seen, all the accumulated characters up to but not
  960.      including the matching double quote are made into a simple string and
  961.      returned.
  962.  
  963. `    The backquote (accent grave) character makes it easier to write programs
  964.      to construct complex data structures by using a template.
  965.  
  966. [change_begin]
  967.  
  968.      Notice of correction. In the first edition, the backquote character <`>
  969.      appearing at the left margin above was inadvertently omitted.
  970.  
  971. [change_end]
  972.  
  973.      As an example, writing
  974.  
  975.      `(cond ((numberp ,x) ,@y) (t (print ,x) ,@y))
  976.  
  977.      is roughly equivalent to writing
  978.  
  979.      (list 'cond
  980.            (cons (list 'numberp x) y)
  981.            (list* 't (list 'print x) y))
  982.  
  983.      The general idea is that the backquote is followed by a template, a
  984.      picture of a data structure to be built. This template is copied, except
  985.      that within the template commas can appear. Where a comma occurs, the form
  986.      following the comma is to be evaluated to produce an object to be inserted
  987.      at that point. Assume b has the value 3; then evaluating the form denoted
  988.      by `(a b ,b ,(+ b 1) b) produces the result (a b 3 4 b).
  989.  
  990.      If a comma is immediately followed by an at-sign (@), then the form
  991.      following the at-sign is evaluated to produce a list of objects. These
  992.      objects are then ``spliced'' into place in the template. For example, if x
  993.      has the value (a b c), then
  994.  
  995.      `(x ,x ,@x foo ,(cadr x) bar ,(cdr x) baz ,@(cdr x))
  996.         => (x (a b c) a b c foo b bar (b c) baz b c)
  997.  
  998.      The backquote syntax can be summarized formally as follows. For each of
  999.      several situations in which backquote can be used, a possible
  1000.      interpretation of that situation as an equivalent form is given. Note that
  1001.      the form is equivalent only in the sense that when it is evaluated it will
  1002.      calculate the correct result. An implementation is quite free to interpret
  1003.      backquote in any way such that a backquoted form, when evaluated, will
  1004.      produce a result equal to that produced by the interpretation shown here.
  1005.  
  1006.         o  `basic is the same as 'basic, that is, (quote basic), for any form
  1007.           basic that is not a list or a general vector.
  1008.  
  1009.         o  `,form is the same as form, for any form, provided that the
  1010.           representation of form does not begin with ``@'' or ``.''. (A similar
  1011.           caveat holds for all occurrences of a form after a comma.)
  1012.  
  1013.         o  `,@form is an error.
  1014.  
  1015.         o  `(x1 x2 x3 ... xn . atom) may be interpreted to mean
  1016.  
  1017.           (append [x1] [x2]
  1018.               [x3] ... [xn] (quote atom))
  1019.  
  1020.           where the brackets are used to indicate a transformation of an xj as
  1021.           follows:
  1022.              +  [form] is interpreted as (list `form), which contains a
  1023.                backquoted form that must then be further interpreted.
  1024.  
  1025.              +  [,form] is interpreted as (list form).
  1026.  
  1027.              +  [,@form] is interpreted simply as form.
  1028.  
  1029.         o  `(x1 x2 x3 ... xn) may be interpreted to mean the same as the
  1030.           backquoted form `(x1 x2 x3 ... xn . nil), thereby reducing it to the
  1031.           previous case.
  1032.  
  1033.         o  `(x1 x2 x3 ... xn . ,form) may be interpreted to mean
  1034.  
  1035.           (append [x1] [x2]
  1036.               [x3] ... [xn] form)
  1037.  
  1038.           where the brackets indicate a transformation of an xj as described
  1039.           above.
  1040.  
  1041.         o  `(x1 x2 x3 ... xn . ,@form) is an error.
  1042.  
  1043.         o  `#(x1 x2 x3 ... xn) may be interpreted to mean
  1044.  
  1045.           (apply #'vector `(x1 x2 x3 ... xn))
  1046.  
  1047.      No other uses of comma are permitted; in particular, it may not appear
  1048.      within the #A or #S syntax.
  1049.  
  1050.      Anywhere ``,@'' may be used, the syntax ``,.'' may be used instead to
  1051.      indicate that it is permissible to destroy the list produced by the form
  1052.      following the ``,.''; this may permit more efficient code, using nconc
  1053.      instead of append, for example.
  1054.  
  1055.      If the backquote syntax is nested, the innermost backquoted form should be
  1056.      expanded first. This means that if several commas occur in a row, the
  1057.      leftmost one belongs to the innermost backquote.
  1058.  
  1059.      Once again, it is emphasized that an implementation is free to interpret a
  1060.      backquoted form as any form that, when evaluated, will produce a result
  1061.      that is equal to the result implied by the above definition. In
  1062.      particular, no guarantees are made as to whether the constructed copy of
  1063.      the template will or will not share list structure with the template
  1064.      itself. As an example, the above definition implies that
  1065.  
  1066.      `((,a b) ,c ,@d)
  1067.  
  1068.      will be interpreted as if it were
  1069.  
  1070.      (append (list (append (list a) (list 'b) 'nil)) (list c) d 'nil)
  1071.  
  1072.      but it could also be legitimately interpreted to mean any of the
  1073.      following.
  1074.  
  1075.      (append (list (append (list a) (list 'b))) (list c) d)
  1076.      (append (list (append (list a) '(b))) (list c) d)
  1077.      (append (list (cons a '(b))) (list c) d)
  1078.      (list* (cons a '(b)) c d)
  1079.      (list* (cons a (list 'b)) c d)
  1080.      (list* (cons a '(b)) c (copy-list d))
  1081.  
  1082.      (There is no good reason why copy-list should be performed, but it is not
  1083.      prohibited.)
  1084.  
  1085. [change_begin]
  1086.  
  1087.      Some users complain that backquote syntax is difficult to read, especially
  1088.      when it is nested. I agree that it can get complicated, but in some
  1089.      situations (such as writing macros that expand into definitions for other
  1090.      macros) such complexity is to be expected, and the alternative is much
  1091.      worse.
  1092.  
  1093.      After I gained some experience in writing nested backquote forms, I found
  1094.      that I was not stopping to analyze the various patterns of nested
  1095.      backquotes and interleaved commas and quotes; instead, I was recognizing
  1096.      standard idioms wholesale, in the same manner that I recognize cadar as
  1097.      the primitive for ``extract the lambda-list from the form ((lambda ...)
  1098.      ...))'' without stopping to analyze it into ``car of cdr of car.'' For
  1099.      example, ,x within a doubly-nested backquote form means ``the value of x
  1100.      available during the second evaluation will appear here once the form has
  1101.      been twice evaluated,'' whereas ,',x means ``the value of x available
  1102.      during the first evaluation will appear here once the form has been twice
  1103.      evaluated'' and ,,x means ``the value of the value of x will appear
  1104.      here.''
  1105.  
  1106.      See appendix C for a systematic set of examples of the use of nested
  1107.      backquotes.
  1108.  
  1109. [change_end]
  1110.  
  1111. ,    The comma character is part of the backquote syntax and is invalid if used
  1112.      other than inside the body of a backquote construction as described above.
  1113.  
  1114.  
  1115. #    This is a dispatching macro character. It reads an optional digit string
  1116.      and then one more character, and uses that character to select a function
  1117.      to run as a macro-character function.
  1118.  
  1119.      The # character also happens to be a non-terminating macro character. This
  1120.      is completely independent of the fact that it is a dispatching macro
  1121.      character; it is a coincidence that the only standard dispatching macro
  1122.      character in Common Lisp is also the only standard non-terminating macro
  1123.      character.
  1124.  
  1125.      See the next section for predefined # macro-character constructions.
  1126.  
  1127. -------------------------------------------------------------------------------
  1128.  
  1129. 22.1.4. Standard Dispatching Macro Character Syntax
  1130.  
  1131. The standard syntax includes forms introduced by the # character. These take
  1132. the general form of a #, a second character that identifies the syntax, and
  1133. following arguments in some form. If the second character is a letter, then
  1134. case is not important; #O and #o are considered to be equivalent, for example.
  1135.  
  1136. Certain # forms allow an unsigned decimal number to appear between the # and
  1137. the second character; some other forms even require it. Those forms that do not
  1138. explicitly permit such a number to appear forbid it.
  1139.  
  1140. ----------------------------------------------------------------
  1141. Table 22-4: Standard # Macro Character Syntax
  1142.  
  1143. #!  undefined *                #<backspace>  signals error
  1144. #"  undefined                  #<tab>        signals error
  1145. ##  reference to #= label      #<newline>    signals error
  1146. #$  undefined                  #<linefeed>   signals error
  1147. #%  undefined                  #<page>       signals error
  1148. #&  undefined                  #<return>     signals error
  1149. #'  function abbreviation      #<space>      signals error
  1150. #(  simple vector              #+      read-time conditional
  1151. #)  signals error              #-      read-time conditional
  1152. #*  bit-vector                 #.      read-time evaluation
  1153. #,  load-time evaluation       #/      undefined
  1154. #0  used for infix arguments   #A, #a  array
  1155. #1  used for infix arguments   #B, #b  binary rational
  1156. #2  used for infix arguments   #C, #c  complex number
  1157. #3  used for infix arguments   #D, #d  undefined
  1158. #4  used for infix arguments   #E, #e  undefined
  1159. #5  used for infix arguments   #F, #f  undefined
  1160. #6  used for infix arguments   #G, #g  undefined
  1161. #7  used for infix arguments   #H, #h  undefined
  1162. #8  used for infix arguments   #I, #i  undefined
  1163. #9  used for infix arguments   #J, #j  undefined
  1164. #:  uninterned symbol          #K, #k  undefined
  1165. #;  undefined                  #L, #l  undefined
  1166. #<  signals error              #M, #m  undefined
  1167. #=  label following object     #N, #n  undefined
  1168. #>  undefined                  #O, #o  octal rational
  1169. #?  undefined *                #P, #p  pathname
  1170. #@  undefined                  #Q, #q  undefined
  1171. #[  undefined *                #R, #r  radix-n rational
  1172. #\  character object           #S, #s  structure
  1173. #]  undefined *                #T, #t  undefined
  1174. #^  undefined                  #U, #u  undefined
  1175. #_  undefined                  #V, #v  undefined
  1176. #`  undefined                  #W, #w  undefined
  1177. #{  undefined *                #X, #x  hexadecimal rational
  1178. #|  balanced comment           #Y, #y  undefined
  1179. #}  undefined *                #Z, #z  undefined
  1180. #~  undefined                  #<rubout> undefined
  1181.  
  1182. The combinations marked by an asterisk are explicitly reserved to the user
  1183. and will never be defined by Common Lisp.
  1184.  
  1185. [change_begin]
  1186.  
  1187. X3J13 voted in June 1989 (PATHNAME-PRINT-READ) to
  1188. specify #P and #p (undefined in the first edition).
  1189. [change_end]
  1190.  
  1191. ----------------------------------------------------------------
  1192.  
  1193. The currently defined # constructs are described below and summarized in table
  1194. 22-4; more are likely to be added in the future. However, the constructs #!,
  1195. #?, #[, #], #{, and #} are explicitly reserved for the user and will never be
  1196. defined by the Common Lisp standard.
  1197.  
  1198. #\   #\x reads in as a character object that represents the character x. Also,
  1199.      #\name reads in as the character object whose name is name.   Note that
  1200.      the backslash allows this construct to be parsed easily by EMACS-like
  1201.      editors.
  1202.  
  1203.      In the single-character case, the character x must be followed by a
  1204.      non-constituent character, lest a name appear to follow the #\. A good
  1205.      model of what happens is that after #\ is read, the reader backs up over
  1206.      the and then reads an extended token, treating the initial as an escape
  1207.      character (whether it really is or not in the current readtable).
  1208.  
  1209.      Uppercase and lowercase letters are distinguished after #\; #\A and #\a
  1210.      denote different character objects. Any character works after #\, even
  1211.      those that are normally special to read, such as parentheses. Non-printing
  1212.      characters may be used after #\, although for them names are generally
  1213.      preferred.
  1214.  
  1215.      #\name reads in as a character object whose name is name (actually, whose
  1216.      name is (string-upcase name); therefore the syntax is case-insensitive).
  1217.      The name should have the syntax of a symbol. The following names are
  1218.      standard across all implementations:
  1219.  
  1220.      newline         The character that represents the division between lines
  1221.      space           The space or blank character
  1222.  
  1223.      The following names are semi-standard; if an implementation supports them,
  1224.      they should be used for the described characters and no others.
  1225.  
  1226.      rubout          The rubout or delete character.
  1227.      page            The form-feed or page-separator character
  1228.      tab             The tabulate character
  1229.      backspace       The backspace character
  1230.      return          The carriage return character
  1231.      linefeed        The line-feed character
  1232.  
  1233.      In some implementations, one or more of these characters might be a
  1234.      synonym for a standard character; the #\Linefeed character might be the
  1235.      same as #\Newline, for example.
  1236.  
  1237.      When the Lisp printer types out the name of a special character, it uses
  1238.      the same table as the #\ reader; therefore any character name you see
  1239.      typed out is acceptable as input (in that implementation). Standard names
  1240.      are always preferred over non-standard names for printing.
  1241.  
  1242.      The following convention is used in implementations that support non-zero
  1243.      bits attributes for character objects. If a name after #\ is longer than
  1244.      one character and has a hyphen in it, then it may be split into the two
  1245.      parts preceding and following the first hyphen; the first part (actually,
  1246.      string-upcase of the first part) may then be interpreted as the name or
  1247.      initial of a bit, and the second part as the name of the character (which
  1248.      may in turn contain a hyphen and be subject to further splitting). For
  1249.      example:
  1250.  
  1251.      #\Control-Space         #\Control-Meta-Tab
  1252.      #\C-M-Return            #\H-S-M-C-Rubout
  1253.  
  1254.      If the character name consists of a single character, then that character
  1255.      is used. Another may be necessary to quote the character.
  1256.  
  1257.      #\Control-%             #\Control-Meta-\"
  1258.      #\Control-\a             #\Meta->
  1259.  
  1260. [old_change_begin]
  1261.  
  1262.      If an unsigned decimal integer appears between the # and , it is
  1263.      interpreted as a font number, to become the font attribute of the
  1264.      character object (see char-font).
  1265.  
  1266. [old_change_end]
  1267.  
  1268. [change_begin]
  1269.  
  1270.      X3J13 voted in March 1989 (CHARACTER-PROPOSAL)   to replace the notion of
  1271.      bits and font attributes with that of implementation-defined attributes.
  1272.      Presumably this eliminates the portable use of this syntax for font
  1273.      information, although the vote did not address this question directly.
  1274.  
  1275. [change_end]
  1276.  
  1277. #'   #'foo is an abbreviation for (function foo). foo may be the printed
  1278.      representation of any Lisp object. This abbreviation may be remembered by
  1279.      analogy with the ' macro character, since the function and quote special
  1280.      forms are similar in form.
  1281.  
  1282. #(   A series of representations of objects enclosed by #( and ) is read as a
  1283.      simple vector of those objects. This is analogous to the notation for
  1284.      lists.
  1285.  
  1286.      If an unsigned decimal integer appears between the # and (, it specifies
  1287.      explicitly the length of the vector. In that case, it is an error if too
  1288.      many objects are specified before the closing ), and if too few are
  1289.      specified, the last object (it is an error if there are none in this case)
  1290.      is used to fill all remaining elements of the vector. For example,
  1291.  
  1292.      #(a b c c c c) #6(a b c c c c) #6(a b c) #6(a b c c)
  1293.  
  1294.      all mean the same thing: a vector of length 6 with elements a, b, and four
  1295.      instances of c. The notation #() denotes an empty vector, as does #0()
  1296.      (which is legitimate because it is not the case that too few elements are
  1297.      specified).
  1298.  
  1299. #*   A series of binary digits (0 and 1) preceded by #* is read as a simple
  1300.      bit-vector containing those bits, the leftmost bit in the series being bit
  1301.      0 of the bit-vector.
  1302.  
  1303.      If an unsigned decimal integer appears between the # and *, it specifies
  1304.      explicitly the length of the vector. In that case, it is an error if too
  1305.      many bits are specified, and if too few are specified the last one (it is
  1306.      an error if there are none in this case) is used to fill all remaining
  1307.      elements of the bit-vector. For example,
  1308.  
  1309.      #*101111     #6*101111     #6*101     #6*1011
  1310.  
  1311.      all mean the same thing: a vector of length 6 with elements 1, 0, 1, 1, 1,
  1312.      and 1. The notation #* denotes an empty bit-vector, as does #0* (which is
  1313.      legitimate because it is not the case that too few elements are
  1314.      specified).
  1315.  
  1316. [change_begin]
  1317.  
  1318.      Compare this to #B, used for expressing integers in binary notation.
  1319.  
  1320. [change_end]
  1321.  
  1322. #:   #:foo requires foo to have the syntax of an unqualified symbol name (no
  1323.      embedded colons). It denotes an uninterned symbol whose name is foo. Every
  1324.      time this syntax is encountered, a different uninterned symbol is created.
  1325.      If it is necessary to refer to the same uninterned symbol more than once
  1326.      in the same expression, the #= syntax may be useful.
  1327.  
  1328. #.   #.foo is read as the object resulting from the evaluation of the Lisp
  1329.      object represented by foo, which may be the printed representation of any
  1330.      Lisp object. The evaluation is done during the read process, when the #.
  1331.      construct is encountered.
  1332.  
  1333. [change_begin]
  1334.  
  1335.      X3J13 voted in June 1989 (DATA-IO)   to add a new reader control variable,
  1336.      *read-eval*. If it is true, the #. reader macro behaves as described
  1337.      above; if it is false, the #. reader macro signals an error.
  1338.  
  1339. [change_end]
  1340.  
  1341.      The #. syntax therefore performs a read-time evaluation of foo. By
  1342.      contrast, #, (see below) performs a load-time evaluation.
  1343.  
  1344.      Both #. and #, allow you to include, in an expression being read, an
  1345.      object that does not have a convenient printed representation; instead of
  1346.      writing a representation for the object, you write an expression that will
  1347.      compute the object.
  1348.  
  1349. [old_change_begin]
  1350.  
  1351. #,   #,foo is read as the object resulting from the evaluation of the Lisp
  1352.      object represented by foo, which may be the printed representation of any
  1353.      Lisp object. The evaluation is done during the read process, unless the
  1354.      compiler is doing the reading, in which case it is arranged that foo will
  1355.      be evaluated when the file of compiled code is loaded. The #, syntax
  1356.      therefore performs a load-time evaluation of foo. By contrast, #. (see
  1357.      above) performs a read-time evaluation. In a sense, #, is like specifying
  1358.      (eval load) to eval-when, whereas #. is more like specifying (eval
  1359.      compile). It makes no difference when loading interpreted code; when code
  1360.      is to be compiled, however, #. specifies compile-time evaluation and #,
  1361.      specifies load-time evaluation.
  1362.  
  1363. [old_change_end]
  1364.  
  1365. [change_begin]
  1366. X3J13 voted in January 1989 (SHARP-COMMA-CONFUSION)   to remove #, from the
  1367. language. X3J13 noted that the first edition failed to make it clear that #,
  1368. can be meaningful only within quoted forms. All sorts of anomalies can arise,
  1369. including inconsistencies between the interpreter and compiler, if #, is not
  1370. properly restricted. See load-time-eval.
  1371. [change_end]
  1372.  
  1373. #B   #brational reads rational in binary (radix 2). For example, #B1101 == 13,
  1374.      and #b101/11 == 5/3.
  1375.  
  1376. [change_begin]
  1377.  
  1378.      Compare this to #*, used for expressing bit-vectors in binary notation.
  1379.  
  1380. [change_end]
  1381.  
  1382. #O   #orational reads rational in octal (radix 8). For example, #o37/15 ==
  1383.      31/13, and #o777 == 511.
  1384.  
  1385. #X   #xrational reads rational in hexadecimal (radix 16). The digits above 9
  1386.      are the letters A through F (the lowercase letters a through f are also
  1387.      acceptable). For example, #xF00 == 3840.
  1388.  
  1389. #nR  #radixrrational reads rational in radix radix. radix must consist of only
  1390.      digits, and it is read in decimal; its value must be between 2 and 36
  1391.      (inclusive).
  1392.  
  1393.      For example, #3r102 is another way of writing 11, and #11R32 is another
  1394.      way of writing 35. For radices larger than 10, letters of the alphabet are
  1395.      used in order for the digits after 9.
  1396.  
  1397. #nA  The syntax #nAobject constructs an n-dimensional array, using object as
  1398.      the value of the :initial-contents argument to make-array.
  1399.  
  1400.      The value of n makes a difference: #2A((0 1 5) (foo 2 (hot dog))), for
  1401.      example, represents a 2-by-3 matrix:
  1402.  
  1403.      0       1       5
  1404.      foo     2       (hot dog)
  1405.  
  1406.      In contrast, #1A((0 1 5) (foo 2 (hot dog))) represents a length-2 array
  1407.      whose elements are lists:
  1408.  
  1409.      (0 1 5)    (foo 2 (hot dog))
  1410.  
  1411.      Furthermore, #0A((0 1 5) (foo 2 (hot dog))) represents a zero-dimensional
  1412.      array whose sole element is a list:
  1413.  
  1414.      ((0 1 5) (foo 2 (hot dog)))
  1415.  
  1416.      Similarly, #0Afoo (or, more readably, #0A foo) represents a
  1417.      zero-dimensional array whose sole element is the symbol foo. The
  1418.      expression #1Afoo would not be legal because foo is not a sequence.
  1419.  
  1420. #S   The syntax #s(name slot1 value1 slot2 value2 ...) denotes a structure.
  1421.      This is legal only if name is the name of a structure already defined by
  1422.      defstruct and if the structure has a standard constructor macro, which it
  1423.      normally will. Let cm stand for the name of this constructor macro; then
  1424.      this syntax is equivalent to
  1425.  
  1426.      #.(cm keyword1 'value1 keyword2 'value2 ...)
  1427.  
  1428.      where each keywordj is the result of computing
  1429.  
  1430.      (intern (string slotj) 'keyword)
  1431.  
  1432.      (This computation is made so that one need not write a colon in front of
  1433.      every slot name.) The net effect is that the constructor macro is called
  1434.      with the specified slots having the specified values (note that one does
  1435.      not write quote marks in the #S syntax). Whatever object the constructor
  1436.      macro returns is returned by the #S syntax.
  1437.  
  1438. [change_begin]
  1439.  
  1440. #P   X3J13 voted in June 1989 (PATHNAME-PRINT-READ)   to define the reader
  1441.      syntax #p"..." to be equivalent to #.(parse-namestring "..."). Presumably
  1442.      this was meant to be taken descriptively and not literally. I would think,
  1443.      for example, that the committee did not wish to quibble over the package
  1444.      in which the name parse-namestring was to be read. Similarly, I would
  1445.      presume that the #p syntax operates normally rather than signaling an
  1446.      error when *read-eval* is false. I interpret the intent of the vote to be
  1447.      that #p reads a following form, which should be a string, that is then
  1448.      converted to a pathname as if by application of the standard function
  1449.      parse-namestring.
  1450.  
  1451. [change_end]
  1452.  
  1453. #n=  The syntax #n=object reads as whatever Lisp object has object as its
  1454.      printed representation. However, that object is labelled by n, a required
  1455.      unsigned decimal integer, for possible reference by the syntax #n#
  1456.      (below). The scope of the label is the expression being read by the
  1457.      outermost call to read. Within this expression the same label may not
  1458.      appear twice.
  1459.  
  1460. #n#  The syntax #n#, where n is a required unsigned decimal integer, serves as
  1461.      a reference to some object labelled by #n=; that is, #n# represents a
  1462.      pointer to the same identical (eq) object labelled by #n=. This permits
  1463.      notation of structures with shared or circular substructure. For example,
  1464.      a structure created in the variable y by this code:
  1465.  
  1466.      (setq x (list 'p 'q))
  1467.      (setq y (list (list 'a 'b) x 'foo x))
  1468.      (rplacd (last y) (cdr y))
  1469.  
  1470.      could be represented in this way:
  1471.  
  1472.      ((a b) . #1=(#2=(p q) foo #2# . #1#))
  1473.  
  1474.      Without this notation, but with *print-length* set to 10, the structure
  1475.      would print in this way:
  1476.  
  1477.      ((a b) (p q) foo (p q) (p q) foo (p q) (p q) foo (p q) ...)
  1478.  
  1479.      A reference #n# may occur only after a label #n=; forward references are
  1480.      not permitted. In addition, the reference may not appear as the labelled
  1481.      object itself (that is, one may not write #n= #n#), because the object
  1482.      labelled by #n= is not well defined in this case.
  1483.  
  1484. #+     The #+ syntax provides a read-time conditionalization facility; the
  1485.      syntax is
  1486.  
  1487.      #+feature form
  1488.  
  1489.      If feature is ``true,'' then this syntax represents a Lisp object whose
  1490.      printed representation is form. If feature is ``false,'' then this syntax
  1491.      is effectively whitespace; it is as if it did not appear.
  1492.  
  1493.      The feature should be the printed representation of a symbol or list. If
  1494.      feature is a symbol, then it is true if and only if it is a member of the
  1495.      list that is the value of the global variable *features*.
  1496.  
  1497. -------------------------------------------------------------------------------
  1498. Compatibility note: MacLisp uses the status special form for this purpose, and
  1499. Lisp Machine Lisp duplicates status essentially only for the sake of (status
  1500. features). The use of a variable allows one to bind the features list, when
  1501. compiling, for example.
  1502. -------------------------------------------------------------------------------
  1503.  
  1504.      Otherwise, feature should be a Boolean expression composed of and, or, and
  1505.      not operators on (recursive) feature expressions.
  1506.  
  1507.      For example, suppose that in implementation A the features spice and perq
  1508.      are true, and in implementation B the feature lispm is true. Then the
  1509.      expressions on the left below are read the same as those on the right in
  1510.      implementation A:
  1511.  
  1512.      (cons #+spice "Spice" #+lispm "Lispm" x)      (cons "Spice" x)
  1513.      (setq a '(1 2 #+perq 43 #+(not perq) 27))     (setq a '(1 2 43))
  1514.      (let ((a 3) #+(or spice lispm) (b 3))         (let ((a 3) (b 3))
  1515.        (foo a))                                      (foo a))
  1516.      (cons a #+perq #-perq b c)                    (cons a c)
  1517.  
  1518.      In implementation B, however, they are read in this way:
  1519.  
  1520.      (cons #+spice "Spice" #+lispm "Lispm" x)      (cons "Lispm" x)
  1521.      (setq a '(1 2 #+perq 43 #+(not perq) 27))     (setq a '(1 2 27))
  1522.      (let ((a 3) #+(or spice lispm) (b 3))         (let ((a 3) (b 3))
  1523.        (foo a))                                      (foo a))
  1524.      (cons a #+perq #-perq b c)                    (cons a c)
  1525.  
  1526.      The #+ construction must be used judiciously if unreadable code is not to
  1527.      result. The user should make a careful choice between read-time
  1528.      conditionalization and run-time conditionalization.
  1529.  
  1530. [old_change_begin]
  1531.  
  1532.      The #+ syntax operates by first reading the feature specification and then
  1533.      skipping over the form if the feature is ``false.'' This skipping of a
  1534.      form is a bit tricky because of the possibility of user-defined macro
  1535.      characters and side effects caused by the #. and #, constructions. It is
  1536.      accomplished by binding the variable *read-suppress* to a non-nil value
  1537.      and then calling the read function. See the description of *read-suppress*
  1538.      for the details of this operation.
  1539.  
  1540. [old_change_end]
  1541.  
  1542. [change_begin]
  1543.  
  1544.      X3J13 voted in January 1989 (SHARP-COMMA-CONFUSION)   to remove #, from
  1545.      the language.
  1546.  
  1547.      X3J13 voted in March 1988 (SHARPSIGN-PLUS-MINUS-PACKAGE)   to specify that
  1548.      the keyword package is the default package during the reading of a feature
  1549.      specification. Thus #+spice means the same thing as #+:spice, and #+(or
  1550.      spice lispm) means the same thing as #+(or :spice :lispm). Symbols in
  1551.      other packages may be used as feature names, but one must use an explicit
  1552.      package prefix to cite one after #+.
  1553.  
  1554. [change_end]
  1555.  
  1556. #-   #-feature form is equivalent to #+(not feature) form.
  1557.  
  1558. #|   #|...|# is treated as a comment by the reader, just as everything from a
  1559.      semicolon to the next newline is treated as a comment. Anything may appear
  1560.      in the comment, except that it must be balanced with respect to other
  1561.      occurrences of #| and |#. Except for this nesting rule, the comment may
  1562.      contain any characters whatsoever.
  1563.  
  1564.      The main purpose of this construct is to allow ``commenting out'' of
  1565.      blocks of code or data. The balancing rule allows such blocks to contain
  1566.      pieces already so commented out. In this respect the #|...|# syntax of
  1567.      Common Lisp differs from the /*...*/ comment syntax used by PL/I and C.
  1568.  
  1569. #<   This is not legal reader syntax. It is conventionally used in the printed
  1570.      representation of objects that cannot be read back in. Attempting to read
  1571.      a #< will cause an error. (More precisely, it is legal syntax, but the
  1572.      macro-character function for #< signals an error.)
  1573.  
  1574. [change_begin]
  1575.  
  1576.      The usual convention for printing unreadable data objects is to print some
  1577.      identifying information (the internal machine address of the object, if
  1578.      nothing else) preceded by #< and followed by >.
  1579.  
  1580.      X3J13 voted in June 1989 (DATA-IO)   to add print-unreadable-object, a
  1581.      macro that prints an object using #<...> syntax and also takes care of
  1582.      checking the variable *print-readably*.
  1583.  
  1584. [change_end]
  1585.  
  1586. #<space>, #<tab>, #<newline>, #<page>, #<return>
  1587.      A # followed by a whitespace character is not legal reader syntax. This
  1588.      prevents abbreviated forms produced via *print-level* cutoff from reading
  1589.      in again, as a safeguard against losing information. (More precisely, this
  1590.      is legal syntax, but the macro-character function for it signals an
  1591.      error.)
  1592.  
  1593. #)   This is not legal reader syntax. This prevents abbreviated forms produced
  1594.      via *print-level* cutoff from reading in again, as a safeguard against
  1595.      losing information. (More precisely, this is legal syntax, but the
  1596.      macro-character function for it signals an error.)
  1597.  
  1598. -------------------------------------------------------------------------------
  1599.  
  1600. 22.1.5. The Readtable
  1601.  
  1602. Previous sections describe the standard syntax accepted by the read function.
  1603. This section discusses the advanced topic of altering the standard syntax
  1604. either to provide extended syntax for Lisp objects or to aid the writing of
  1605. other parsers.
  1606.  
  1607. There is a data structure called the readtable that is used to control the
  1608. reader. It contains information about the syntax of each character equivalent
  1609. to that in table 22-1. It is set up exactly as in table 22-1 to give the
  1610. standard Common Lisp meanings to all the characters, but the user can change
  1611. the meanings of characters to alter and customize the syntax of characters. It
  1612. is also possible to have several readtables describing different syntaxes and
  1613. to switch from one to another by binding the variable *readtable*.
  1614.  
  1615. [old_change_begin]
  1616. Even if an implementation supports characters with non-zero bits and font
  1617. attributes, it need not (but may) allow for such characters to have syntax
  1618. descriptions in the readtable. However, every character of type string-char
  1619. must be represented in the readtable.
  1620. [old_change_end]
  1621.  
  1622. [change_begin]
  1623. X3J13 voted in March 1989 (CHARACTER-PROPOSAL)   to remove the type string-char
  1624. and to replace the bits and font attributes with the notion of
  1625. implementation-defined attributes. If any implementation-defined attributes are
  1626. supported, an implementation may (but need not) allow for such characters to
  1627. have syntax descriptions in the readtable. Characters that do not have
  1628. non-standard values for any implementation-defined attribute must be
  1629. represented in the readtable.
  1630. [change_end]
  1631.  
  1632. [Variable]
  1633. *readtable*
  1634.  
  1635. The value of *readtable* is the current readtable. The initial value of this is
  1636. a readtable set up for standard Common Lisp syntax. You can bind this variable
  1637. to temporarily change the readtable being used.
  1638.  
  1639. To program the reader for a different syntax, a set of functions are provided
  1640. for manipulating readtables. Normally, you should begin with a copy of the
  1641. standard Common Lisp readtable and then customize the individual characters
  1642. within that copy.
  1643.  
  1644. [Function]
  1645. copy-readtable &optional from-readtable to-readtable
  1646.  
  1647. A copy is made of from-readtable, which defaults to the current readtable (the
  1648. value of the global variable *readtable*). If from-readtable is nil, then a
  1649. copy of a standard Common Lisp readtable is made. For example,
  1650.  
  1651. (setq *readtable* (copy-readtable nil))
  1652.  
  1653. will restore the input syntax to standard Common Lisp syntax, even if the
  1654. original readtable has been clobbered (assuming it is not so badly clobbered
  1655. that you cannot type in the above expression!). On the other hand,
  1656.  
  1657. (setq *readtable* (copy-readtable))
  1658.  
  1659. will merely replace the current readtable with a copy of itself.
  1660.  
  1661. If to-readtable is unsupplied or nil, a fresh copy is made. Otherwise,
  1662. to-readtable must be a readtable, which is destructively copied into.
  1663.  
  1664. [Function]
  1665. readtablep object
  1666.  
  1667. readtablep is true if its argument is a readtable, and otherwise is false.
  1668.  
  1669. (readtablep x) == (typep x 'readtable)
  1670.  
  1671. [Function]
  1672. set-syntax-from-char to-char from-char &optional to-readtable from-readtable
  1673.  
  1674. This makes the syntax of to-char in to-readtable be the same as the syntax of
  1675. from-char in from-readtable. The to-readtable defaults to the current readtable
  1676. (the value of the global variable *readtable*), and from-readtable defaults to
  1677. nil, meaning to use the syntaxes from the standard Lisp readtable.
  1678.  
  1679. [change_begin]
  1680. X3J13 voted in January 1989 (ARGUMENTS-UNDERSPECIFIED)   to clarify that the
  1681. to-char and from-char must each be a character.
  1682. [change_end]
  1683.  
  1684. Only attributes as shown in table 22-1 are copied; moreover, if a macro
  1685. character is copied, the macro definition function is copied also. However,
  1686. attributes as shown in table 22-3 are not copied; they are ``hard-wired'' into
  1687. the extended-token parser. For example, if the definition of S is copied to *,
  1688. then * will become a constituent that is alphabetic but cannot be used as an
  1689. exponent indicator for short-format floating-point number syntax.
  1690.  
  1691. It works to copy a macro definition from a character such as " to another
  1692. character; the standard definition for " looks for another character that is
  1693. the same as the character that invoked it. It doesn't work to copy the
  1694. definition of ( to {, for example; it can be done, but it lets one write lists
  1695. in the form {a b c), not {a b c}, because the definition always looks for a
  1696. closing parenthesis, not a closing brace. See the function read-delimited-list,
  1697. which is useful in this connection.
  1698.  
  1699. [change_begin]
  1700. X3J13 voted in January 1989 (RETURN-VALUES-UNSPECIFIED)   to specify that the
  1701. set-syntax-from-char function returns t.
  1702. [change_end]
  1703.  
  1704. [Function]
  1705.  
  1706. set-macro-character char function &optional
  1707.          non-terminating-p readtable
  1708. get-macro-character char &optional readtable
  1709.  
  1710. set-macro-character causes char to be a macro character that when seen by read
  1711. causes function to be called. If non-terminating-p is not nil (it defaults to
  1712. nil), then it will be a non-terminating macro character: it may be embedded
  1713. within extended tokens. set-macro-character returns t.
  1714.  
  1715. get-macro-character returns the function associated with char and, as a second
  1716. value, returns the non-terminating-p flag; it returns nil if char does not have
  1717. macro-character syntax. In each case, readtable defaults to the current
  1718. readtable.
  1719.  
  1720. [change_begin]
  1721. X3J13 voted in January 1989 (GET-MACRO-CHARACTER-READTABLE)   to specify that
  1722. if nil is explicitly passed as the second argument to get-macro-character, then
  1723. the standard readtable is used. This is consistent with the behavior of
  1724. copy-readtable.
  1725. [change_end]
  1726.  
  1727. The function is called with two arguments, stream and char. The stream is the
  1728. input stream, and char is the macro character itself. In the simplest case,
  1729. function may return a Lisp object. This object is taken to be that whose
  1730. printed representation was the macro character and any following characters
  1731. read by the function. As an example, a plausible definition of the standard
  1732. single quote character is:
  1733.  
  1734. (defun single-quote-reader (stream char)
  1735.   (declare (ignore char))
  1736.   (list 'quote (read stream t nil t)))
  1737.  
  1738. (set-macro-character #\' #'single-quote-reader)
  1739.  
  1740. (Note that t is specified for the recursive-p argument to read; see section
  1741. 22.2.1.) The function reads an object following the single-quote and returns a
  1742. list of the symbol quote and that object. The char argument is ignored.
  1743.  
  1744. The function may choose instead to return zero values (for example, by using
  1745. (values) as the return expression). In this case, the macro character and
  1746. whatever it may have read contribute nothing to the object being read. As an
  1747. example, here is a plausible definition for the standard semicolon (comment)
  1748. character:
  1749.  
  1750. (defun semicolon-reader (stream char)
  1751.   (declare (ignore char))
  1752.   ;; First swallow the rest of the current input line.
  1753.   ;; End-of-file is acceptable for terminating the comment.
  1754.   (do () ((char= (read-char stream nil #\Newline t) #\Newline)))
  1755.   ;; Return zero values.
  1756.   (values))
  1757.  
  1758. (set-macro-character #\; #'semicolon-reader)
  1759.  
  1760. (Note that t is specified for the recursive-p argument to read-char; see
  1761. section 22.2.1.)
  1762.  
  1763. The function should not have any side effects other than on the stream. Because
  1764. of backtracking and restarting of the read operation, front ends (such as
  1765. editors and rubout handlers) to the reader may cause function to be called
  1766. repeatedly during the reading of a single expression in which the macro
  1767. character only appears once.
  1768.  
  1769. -------------------------------------------------------------------------------
  1770. Compatibility note: The ability to return either zero or one value is the
  1771. closest Common Lisp macro characters come to the splicing macro characters of
  1772. MacLisp or the splice macro characters of Interlisp. The Common Lisp definition
  1773. does not allow the splicing of arbitrarily many values, but it does allow a
  1774. macro-character function to decide after it is invoked whether or not to yield
  1775. a value, an option not possible in MacLisp or Interlisp.
  1776.  
  1777. MacLisp has nothing equivalent to non-terminating macro characters. The
  1778. Interlisp equivalents of terminating and non-terminating macro characters are
  1779. macro characters with the ALWAYS or FIRST option, respectively. Common Lisp has
  1780. nothing equivalent to the Interlisp ALONE macro-character option.
  1781. -------------------------------------------------------------------------------
  1782.  
  1783. [change_begin]
  1784. Here is an example of a more elaborate set of read-macro characters that I used
  1785. in the implementation of the original simulator for Connection Machine Lisp
  1786. [44,57], a parallel dialect of Common Lisp. This simulator was used to gain
  1787. experience with the language before freezing its design for full-scale
  1788. implementation on a Connection Machine computer system. This example
  1789. illustrates the typical manner in which a language designer can embed a new
  1790. language within the syntactic and semantic framework of Lisp, saving the effort
  1791. of designing an implementation from scratch.
  1792.  
  1793. Connection Machine Lisp introduces a new data type called a xapping, which is
  1794. simply an unordered set of ordered pairs of Lisp objects. The first element of
  1795. each pair is called the index and the second element the value. We say that the
  1796. xapping maps each index to its corresponding value. No two pairs of the same
  1797. xapping may have the same (that is, eql) index. Xappings may be finite or
  1798. infinite sets of pairs; only certain kinds of infinite xappings are required,
  1799. and special representations are used for them.
  1800.  
  1801. A finite xapping is notated by writing the pairs between braces, separated by
  1802. whitespace. A pair is notated by writing the index and the value, separated by
  1803. a right arrow (or an exclamation point if the host Common Lisp has no
  1804. right-arrow character).
  1805.  
  1806. -------------------------------------------------------------------------------
  1807. Remark: The original language design used the right arrow; the exclamation
  1808. point was chosen to replace it on ASCII-only terminals because it is one of the
  1809. six characters [ ] { } ! ? reserved by Common Lisp to the user.
  1810.  
  1811. While preparing the TeX manuscript for this book I made a mistake in font
  1812. selection and discovered that by an absolutely incredible coincidence the right
  1813. arrow has the same numerical code (octal 41) within TeX fonts as the ASCII
  1814. exclamation point. The result was that although the manuscript called for right
  1815. arrows, exclamation points came out in the printed copy. Imagine my
  1816. astonishment!
  1817. -------------------------------------------------------------------------------
  1818.  
  1819. Here is an example of a xapping that maps three symbols to strings:
  1820.  
  1821. {moe->"Oh, a wise guy, eh?" larry->"Hey, what's the idea?"
  1822.   curly->"Nyuk, nyuk, nyuk!"}
  1823.  
  1824. For convenience there are certain abbreviated notations. If the index and value
  1825. for a pair are the same object x, then instead of having to write ``x->x'' (or,
  1826. worse yet, ``#43=x->#43#'') we may write simply x for the pair. If all pairs of
  1827. a xapping are of this form, we call the xapping a xet. For example, the
  1828. notation
  1829.  
  1830. {baseball chess cricket curling bocce 43-man-squamish}
  1831.  
  1832. is entirely equivalent in meaning to
  1833.  
  1834. {baseball->baseball curling->curling cricket->cricket
  1835.  chess->chess bocce->bocce 43-man-squamish->43-man-squamish}
  1836.  
  1837. namely a xet of symbols naming six sports.
  1838.  
  1839. Another useful abbreviation covers the situation where the n pairs of a finite
  1840. xapping are integers, collectively covering a range from zero to n-1. This kind
  1841. of xapping is called a xector and may be notated by writing the values between
  1842. brackets in ascending order of their indices. Thus
  1843.  
  1844. [tinker evers chance]
  1845.  
  1846. is merely an abbreviation for
  1847.  
  1848. {tinker->0 evers->1 chance->2}
  1849.  
  1850. There are two kinds of infinite xapping: constant and universal. A constant
  1851. xapping {->z} maps every object to the same value z. The universal xapping {->}
  1852. maps every object to itself and is therefore the xet of all Lisp objects,
  1853. sometimes called simply the universe. Both kinds of infinite xet may be
  1854. modified by explicitly writing exceptions. One kind of exception is simply a
  1855. pair, which specifies the value for a particular index; the other kind of
  1856. exception is simply k->indicating that the xapping does not have a pair with
  1857. index k after all. Thus the notation
  1858.  
  1859. {sky->blue grass->green idea->glass->->red}
  1860.  
  1861. indicates a xapping that maps sky to blue, grass to green, and every other
  1862. object except idea and glass to red. Note well that the presence or absence of
  1863. whitespace on either side of an arrow is crucial to the correct interpretation
  1864. of the notation.
  1865.  
  1866. Here is the representation of a xapping as a structure:
  1867.  
  1868. (defstruct
  1869.   (xapping (:print-function print-xapping)
  1870.            (:constructor xap
  1871.              (domain range &optional
  1872.               (default ':unknown defaultp)
  1873.               (infinite (and defaultp :constant))
  1874.               (exceptions '()))))
  1875.   domain
  1876.   range
  1877.   default
  1878.   (infinite nil :type (member nil :constant :universal)
  1879.   exceptions)
  1880.  
  1881. The explicit pairs are represented as two parallel lists, one of indexes
  1882. (domain) and one of values (range). The default slot is the default value,
  1883. relevant only if the infinite slot is :constant. The exceptions slot is a list
  1884. of indices for which there are no values. (See the end of section 22.3.3 for
  1885. the definition of print-xapping.)
  1886.  
  1887. Here, then, is the code for reading xectors in bracket notation:
  1888.  
  1889. (defun open-bracket-macro-char (stream macro-char)
  1890.   (declare (ignore macro-char))
  1891.   (let ((range (read-delimited-list #\] stream t)))
  1892.     (xap (iota-list (length range)) range)))
  1893.  
  1894. (set-macro-character #\[ #'open-bracket-macro-char)
  1895. (set-macro-character #\] (get-macro-character #\) ))
  1896.  
  1897. (defun iota-list (n)     ;Return list of integers from 0 to n-1
  1898.   (do ((j (- n 1) (- j 1))
  1899.        (z '() (cons j z)))
  1900.       ((< j 0) z)))
  1901.  
  1902. The code for reading xappings in the more general brace notation, with all the
  1903. possibilities for xets (or individual xet pairs), infinite xappings, and
  1904. exceptions, is a bit more complicated; it is shown in table 22-5. That code is
  1905. used in conjunction with the initializations
  1906.  
  1907. (set-macro-character #\{ #'open-brace-macro-char)
  1908. (set-macro-character #\} (get-macro-character #\) ))
  1909.  
  1910.  
  1911. ----------------------------------------------------------------
  1912. Table 22-5: Macro Character Definition for Xapping Syntax
  1913.  
  1914. (defun open-brace-macro-char (s macro-char)
  1915.   (declare (ignore macro-char))
  1916.   (do ((ch (peek-char t s t nil t) (peek-char t s t nil t))
  1917.        (domain '())  (range '())  (exceptions '()))
  1918.       ((char= ch #\})
  1919.        (read-char s t nil t)
  1920.        (construct-xapping (reverse domain) (reverse range)))
  1921.     (cond ((char= ch #\->)
  1922.            (read-char s t nil t)
  1923.            (let ((nextch (peek-char nil s t nil t)))
  1924.              (cond ((char= nextch #\})
  1925.                     (read-char s t nil t)
  1926.                     (return (xap (reverse domain)
  1927.                                  (reverse range)
  1928.                                  nil :universal exceptions)))
  1929.                    (t (let ((item (read s t nil t)))
  1930.                         (cond ((char= (peek-char t s t nil t) #\})
  1931.                                (read-char s t nil t)
  1932.                                (return (xap (reverse domain)
  1933.                                             (reverse range)
  1934.                                             item :constant
  1935.                                             exceptions)))
  1936.                               (t (reader-error s
  1937.                                    "Default -> item must be last"))))))))
  1938.           (t (let ((item (read-preserving-whitespace s t nil t))
  1939.                    (nextch (peek-char nil s t nil t)))
  1940.                (cond ((char= nextch #\->)
  1941.                       (read-char s t nil t)
  1942.                       (cond ((member (peek-char nil s t nil t)
  1943.                                      '(#\Space #\Tab #\Newline))
  1944.                              (push item exceptions))
  1945.                             (t (push item domain)
  1946.                                (push (read s t nil t) range))))
  1947.                      ((char= nch #\})
  1948.                       (read-char s t nil t)
  1949.                       (push item domain)
  1950.                       (push item range)
  1951.                       (return (xap (reverse domain) (reverse range))))
  1952.                      (t (push item domain)
  1953.                         (push item range))))))))
  1954.  
  1955. ----------------------------------------------------------------
  1956.  
  1957. [change_end]
  1958.  
  1959. [Function]
  1960.  
  1961. make-dispatch-macro-character char
  1962.       &optional non-terminating-p readtable
  1963.  
  1964. This causes the character char to be a dispatching macro character in readtable
  1965. (which defaults to the current readtable). If non-terminating-p is not nil (it
  1966. defaults to nil), then it will be a non-terminating macro character: it may be
  1967. embedded within extended tokens. make-dispatch-macro-character returns t.
  1968.  
  1969. Initially every character in the dispatch table has a character-macro function
  1970. that signals an error. Use set-dispatch-macro-character to define entries in
  1971. the dispatch table.
  1972.  
  1973. [change_begin]
  1974. X3J13 voted in January 1989 (ARGUMENTS-UNDERSPECIFIED)   to clarify that char
  1975. must be a character.
  1976. [change_end]
  1977.  
  1978. [Function]
  1979.  
  1980. set-dispatch-macro-character disp-char sub-char function
  1981.     &optional readtable
  1982. get-dispatch-macro-character disp-char sub-char
  1983.     &optional readtable
  1984.  
  1985. set-dispatch-macro-character causes function to be called when the disp-char
  1986. followed by sub-char is read. The readtable defaults to the current readtable.
  1987. The arguments and return values for function are the same as for normal macro
  1988. characters except that function gets sub-char, not disp-char, as its second
  1989. argument and also receives a third argument that is the non-negative integer
  1990. whose decimal representation appeared between disp-char and sub-char, or nil if
  1991. no decimal integer appeared there.
  1992.  
  1993. The sub-char may not be one of the ten decimal digits; they are always reserved
  1994. for specifying an infix integer argument. Moreover, if sub-char is a lowercase
  1995. character (see lower-case-p), its uppercase equivalent is used instead. (This
  1996. is how the rule is enforced that the case of a dispatch sub-character doesn't
  1997. matter.)
  1998.  
  1999. set-dispatch-macro-character returns t.
  2000.  
  2001. get-dispatch-macro-character returns the macro-character function for sub-char
  2002. under disp-char, or nil if there is no function associated with sub-char.
  2003.  
  2004. If the sub-char is one of the ten decimal digits 0 1 2 3 4 5 6 7 8 9,
  2005. get-dispatch-macro-character always returns nil. If sub-char is a lowercase
  2006. character, its uppercase equivalent is used instead.
  2007.  
  2008. [change_begin]
  2009. X3J13 voted in January 1989 (GET-MACRO-CHARACTER-READTABLE)   to specify that
  2010. if nil is explicitly passed as the second argument to
  2011. get-dispatch-macro-character, then the standard readtable is used. This is
  2012. consistent with the behavior of copy-readtable.
  2013. [change_end]
  2014.  
  2015. For either function, an error is signaled if the specified disp-char is not in
  2016. fact a dispatch character in the specified readtable. It is necessary to use
  2017. make-dispatch-macro-character to set up the dispatch character before
  2018. specifying its sub-characters.
  2019.  
  2020. As an example, suppose one would like #$foo to be read as if it were (dollars
  2021. foo). One might say:
  2022.  
  2023. (defun |#$-reader| (stream subchar arg)
  2024.   (declare (ignore subchar arg))
  2025.   (list 'dollars (read stream t nil t)))
  2026.  
  2027. (set-dispatch-macro-character #\# #\$ #'|#$-reader|)
  2028.  
  2029. -------------------------------------------------------------------------------
  2030. Compatibility note: This macro-character mechanism is different from those in
  2031. MacLisp, Interlisp, and Lisp Machine Lisp. Recently Lisp systems have
  2032. implemented very general readers, even readers so programmable that they can
  2033. parse arbitrary compiled BNF grammars. Unfortunately, these readers can be
  2034. complicated to use. This design is an attempt to make the reader as simple as
  2035. possible to understand, use, and implement. Splicing macros have been
  2036. eliminated; a recent informal poll indicates that no one uses them to produce
  2037. other than zero or one value. The ability to access parts of the object
  2038. preceding the macro character has been eliminated. The MacLisp
  2039. single-character-object feature has been eliminated because it is seldom used
  2040. and trivially obtainable by defining a macro.
  2041.  
  2042. The user is encouraged to turn off most macro characters, turn others into
  2043. single-character-object macros, and then use read purely as a lexical analyzer
  2044. on top of which to build a parser. It is unnecessary, however, to cater to more
  2045. complex lexical analysis or parsing than that needed for Common Lisp.
  2046. -------------------------------------------------------------------------------
  2047.  
  2048. [change_begin]
  2049.  
  2050. [Function]
  2051. readtable-case readtable
  2052.  
  2053. X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to introduce the function
  2054. readtable-case to control the reader's interpretation of case. It provides
  2055. access to a slot in a readtable, and may be used with setf to alter the state
  2056. of that slot. The possible values for the slot are :upcase, :downcase,
  2057. :preserve, and :invert; the readtable-case for the standard readtable is
  2058. :upcase. Note that copy-readtable is required to copy the readtable-case slot
  2059. along with all other readtable information.
  2060.  
  2061. Once the reader has accumulated a token as described in section 22.1.1, if the
  2062. token is a symbol, ``replaceable'' characters (unescaped uppercase or lowercase
  2063. constituent characters) may be modified under the control of the readtable-case
  2064. of the current readtable:
  2065.  
  2066.    *  For :upcase, replaceable characters are converted to uppercase. (This was
  2067.      the behavior specified by the first edition.)
  2068.  
  2069.    *  For :downcase, replaceable characters are converted to lowercase.
  2070.  
  2071.    *  For :preserve, the cases of all characters remain unchanged.
  2072.  
  2073.    *  For :invert, if all of the replaceable letters in the extended token are
  2074.      of the same case, they are all converted to the opposite case; otherwise
  2075.      the cases of all characters in that token remain unchanged.
  2076.  
  2077. As an illustration, consider the following code.
  2078.  
  2079. (let ((*readtable* (copy-readtable nil)))
  2080.   (format t "READTABLE-CASE  Input   Symbol-name~
  2081.            ~%-----------------------------------~
  2082.            ~%")
  2083.   (dolist (readtable-case '(:upcase :downcase :preserve :invert))
  2084.     (setf (readtable-case *readtable*) readtable-case)
  2085.     (dolist (input '("ZEBRA" "Zebra" "zebra"))
  2086.       (format t ":~A~16T~A~24T~A~%"
  2087.                 (string-upcase readtable-case)
  2088.                 input
  2089.                 (symbol-name (read-from-string input)))))))
  2090.  
  2091. The output from this test code should be
  2092.  
  2093. READTABLE-CASE  Input   Symbol-name
  2094. ------------
  2095. :UPCASE         ZEBRA   ZEBRA
  2096. :UPCASE         Zebra   ZEBRA
  2097. :UPCASE         zebra   ZEBRA
  2098. :DOWNCASE       ZEBRA   zebra
  2099. :DOWNCASE       Zebra   zebra
  2100. :DOWNCASE       zebra   zebra
  2101. :PRESERVE       ZEBRA   ZEBRA
  2102. :PRESERVE       Zebra   Zebra
  2103. :PRESERVE       zebra   zebra
  2104. :INVERT         ZEBRA   zebra
  2105. :INVERT         Zebra   Zebra
  2106. :INVERT         zebra   ZEBRA
  2107.  
  2108. The readtable-case of the current readtable also affects the printing of
  2109. symbols (see *print-case* and *print-escape*).
  2110. [change_end]
  2111.  
  2112. -------------------------------------------------------------------------------
  2113.  
  2114. 22.1.6. What the Print Function Produces
  2115.  
  2116. The Common Lisp printer is controlled by a number of special variables. These
  2117. are referred to in the following discussion and are fully documented at the end
  2118. of this section.
  2119.  
  2120. How an expression is printed depends on its data type, as described in the
  2121. following paragraphs.
  2122.  
  2123. Integers
  2124.      If appropriate, a radix specifier may be printed; see the variable
  2125.      *print-radix*. If an integer is negative, a minus sign is printed and then
  2126.      the absolute value of the integer is printed. Integers are printed in the
  2127.      radix specified by the variable *print-base* in the usual positional
  2128.      notation, most significant digit first. The number zero is represented by
  2129.      the single digit 0 and never has a sign. A decimal point may then be
  2130.      printed, depending on the value of *print-radix*.
  2131.  
  2132. Ratios
  2133.      If appropriate, a radix specifier may be printed; see the variable
  2134.      *print-radix*. If the ratio is negative, a minus sign is printed. Then the
  2135.      absolute value of the numerator is printed, as for an integer; then a /;
  2136.      then the denominator. The numerator and denominator are both printed in
  2137.      the radix specified by the variable *print-base*; they are obtained as if
  2138.      by the numerator and denominator functions, and so ratios are always
  2139.      printed in reduced form (lowest terms).
  2140.  
  2141. Floating-point numbers
  2142.      If the sign of the number (as determined by the function float-sign) is
  2143.      negative, then a minus sign is printed. Then the magnitude is printed in
  2144.      one of two ways. If the magnitude of the floating-point number is either
  2145.      zero or between    (inclusive) and    (exclusive), it may be printed as
  2146.      the integer part of the number, then a decimal point, followed by the
  2147.      fractional part of the number; there is always at least one digit on each
  2148.      side of the decimal point. If the format of the number does not match that
  2149.      specified by the variable *read-default-float-format*, then the exponent
  2150.      marker for that format and the digit 0 are also printed. For example, the
  2151.      base of the natural logarithms as a short-format floating-point number
  2152.      might be printed as 2.71828S0.
  2153.  
  2154.      For non-zero magnitudes outside of the range    to   , a floating-point
  2155.      number will be printed in ``computerized scientific notation.'' The
  2156.      representation of the number is scaled to be between 1 (inclusive) and 10
  2157.      (exclusive) and then printed, with one digit before the decimal point and
  2158.      at least one digit after the decimal point. Next the exponent marker for
  2159.      the format is printed, except that if the format of the number matches
  2160.      that specified by the variable *read-default-float-format*, then the
  2161.      exponent marker E is used. Finally, the power of 10 by which the fraction
  2162.      must be multiplied to equal the original number is printed as a decimal
  2163.      integer. For example, Avogadro's number as a short-format floating-point
  2164.      number might be printed as 6.02S23.
  2165.  
  2166. Complex numbers
  2167.      A complex number is printed as #C, an open parenthesis, the printed
  2168.      representation of its real part, a space, the printed representation of
  2169.      its imaginary part, and finally a close parenthesis.
  2170.  
  2171. [old_change_begin]
  2172.  
  2173. Characters
  2174.      When *print-escape* is nil, a character prints as itself; it is sent
  2175.      directly to the output stream. When *print-escape* is not nil, then #\
  2176.      syntax is used. For example, the printed representation of the character
  2177.      #\A with control and meta bits on would be #\CONTROL-META-A, and that of
  2178.      #\a with control and meta bits on would be #\CONTROL-META-\a.
  2179.  
  2180. [old_change_end]
  2181.  
  2182. [change_begin]
  2183.  
  2184.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2185.      is not nil then every object must be printed in a readable form,
  2186.      regardless of other printer control variables. For characters, the
  2187.      simplest approach is always to use #\ syntax when *print-readably* is not
  2188.      nil, regardless of the value of *print-escape*.
  2189.  
  2190. [change_end]
  2191.  
  2192. [old_change_begin]
  2193.  
  2194. Symbols
  2195.      When *print-escape* is nil, only the characters of the print name of the
  2196.      symbol are output (but the case in which to print any uppercase characters
  2197.      in the print name is controlled by the variable *print-case*).
  2198.  
  2199. [old_change_end]
  2200.  
  2201. [change_begin]
  2202.  
  2203.      X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to specify that the new
  2204.      readtable-case slot of the current readtable also controls the case in
  2205.      which letters (whether uppercase or lowercase) in the print name of a
  2206.      symbol are output, no matter what the value of *print-escape*.
  2207.  
  2208. [change_end]
  2209.  
  2210. [old_change_begin]
  2211.  
  2212.      The remaining paragraphs describing the printing of symbols cover the
  2213.      situation when *print-escape* is not nil.
  2214.  
  2215. [old_change_end]
  2216.  
  2217. [change_begin]
  2218.  
  2219.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2220.      is not nil then every object must be printed in a readable form,
  2221.      regardless of other printer control variables. For symbols, the simplest
  2222.      approach is to print them, when *print-readably* is not nil, as if
  2223.      *print-escape* were not nil, regardless of the actual value of
  2224.      *print-escape*.
  2225.  
  2226. [change_end]
  2227.  
  2228.      Backslashes and vertical bars | are included as required. In particular,
  2229.      backslash or vertical-bar syntax is used when the name of the symbol would
  2230.      be otherwise treated by the reader as a potential number (see section
  2231.      22.1.2). In making this decision, it is assumed that the value of
  2232.      *print-base* being used for printing would be used as the value of
  2233.      *read-base* used for reading; the value of *read-base* at the time of
  2234.      printing is irrelevant. For example, if the value of *print-base* were 16
  2235.      when printing the symbol face, it would have to be printed as FACE or Face
  2236.      or |FACE|, because the token face would be read as a hexadecimal number
  2237.      (decimal value 64206) if *read-base* were 16.
  2238.  
  2239. [old_change_begin]
  2240.  
  2241.      The case in which to print any uppercase characters in the print name is
  2242.      controlled by the variable *print-case*.
  2243.  
  2244. [old_change_end]
  2245.  
  2246. [change_begin]
  2247.  
  2248.      X3J13 voted in June 1989 (PRINT-CASE-PRINT-ESCAPE-INTERACTION)   to
  2249.      clarify the interaction of *print-case* with *print-escape*; see
  2250.      *print-case*.
  2251.  
  2252. [change_end]
  2253.  
  2254.      As a special case [no pun intended], nil may sometimes be printed as ()
  2255.      instead, when *print-escape* and *print-pretty* are both not nil.
  2256.  
  2257.      Package prefixes may be printed (using colon syntax) if necessary. The
  2258.      rules for package qualifiers are as follows. When the symbol is printed,
  2259.      if it is in the keyword package, then it is printed with a preceding
  2260.      colon; otherwise, if it is accessible in the current package, it is
  2261.      printed without any qualification; otherwise, it is printed with
  2262.      qualification. See chapter 11.
  2263.  
  2264. [old_change_begin]
  2265.  
  2266.      A symbol that is uninterned (has no home package) is printed preceded by
  2267.      #: if the variables *print-gensym* and *print-escape* are both non-nil; if
  2268.      either is nil, then the symbol is printed without a prefix, as if it were
  2269.      in the current package.
  2270.  
  2271. [old_change_end]
  2272.  
  2273. [change_begin]
  2274.  
  2275.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2276.      is not nil then every object must be printed in a readable form,
  2277.      regardless of other printer control variables. For uninterned symbols, the
  2278.      simplest approach is to print them, when *print-readably* is not nil, as
  2279.      if *print-escape* and *print-gensym* were not nil, regardless of their
  2280.      actual values.
  2281.  
  2282. [change_end]
  2283.  
  2284. -------------------------------------------------------------------------------
  2285. Implementation note: Because the #: syntax does not intern the following
  2286. symbol, it is necessary to use circular-list syntax if *print-circle* is not
  2287. nil and the same uninterned symbol appears several times in an expression to be
  2288. printed. For example, the result of
  2289.  
  2290. (let ((x (make-symbol "FOO"))) (list x x))
  2291.  
  2292. would be printed as
  2293.  
  2294. (#:foo #:foo)
  2295.  
  2296. if *print-circle* were nil, but as
  2297.  
  2298. (#1=#:foo #1#)
  2299.  
  2300. if *print-circle* were not nil.
  2301. -------------------------------------------------------------------------------
  2302.  
  2303. [old_change_begin]
  2304.  
  2305.      The case in which symbols are to be printed is controlled by the variable
  2306.      *print-case*.
  2307.  
  2308. [old_change_end]
  2309.  
  2310. [change_begin]
  2311.  
  2312.      It is also controlled by *print-escape* and the readtable-case slot of the
  2313.      current readtable (the value of *readtable*).
  2314.  
  2315. [change_end]
  2316.  
  2317. [old_change_begin]
  2318.  
  2319. Strings
  2320.      The characters of the string are output in order. If *print-escape* is not
  2321.      nil, a double quote is output before and after, and all double quotes and
  2322.      single escape characters are preceded by backslash. The printing of
  2323.      strings is not affected by *print-array*. If the string has a fill
  2324.      pointer, then only those characters below the fill pointer are printed.
  2325.  
  2326. [old_change_end]
  2327.  
  2328. [change_begin]
  2329.  
  2330.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2331.      is not nil then every object must be printed in a readable form,
  2332.      regardless of other printer control variables. For strings, the simplest
  2333.      approach is to print them, when *print-readably* is not nil, as if
  2334.      *print-escape* were not nil, regardless of the actual value of
  2335.      *print-escape*.
  2336.  
  2337. [change_end]
  2338.  
  2339. Conses
  2340.      Wherever possible, list notation is preferred over dot notation. Therefore
  2341.      the following algorithm is used:
  2342.        1.  Print an open parenthesis, (.
  2343.        2.  Print the car of the cons.
  2344.        3.  If the cdr is a cons, make it the current cons, print a space, and
  2345.           go to step 2.
  2346.        4.  If the cdr is not null, print a space, a dot, a space, and the cdr.
  2347.        5.  Print a close parenthesis, ).
  2348.  
  2349.      This form of printing is clearer than showing each individual cons cell.
  2350.      Although the two expressions below are equivalent, and the reader will
  2351.      accept either one and produce the same data structure, the printer will
  2352.      always print such a data structure in the second form.
  2353.  
  2354.      (a . (b . ((c . (d . nil)) . (e . nil))))
  2355.  
  2356.      (a b (c d) e)
  2357.  
  2358. [old_change_begin]
  2359.  
  2360.      The printing of conses is affected by the variables *print-level* and
  2361.      *print-length*.
  2362.  
  2363. [old_change_end]
  2364.  
  2365. [change_begin]
  2366.  
  2367.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2368.      is not nil then every object must be printed in a readable form,
  2369.      regardless of other printer control variables. For conses, the simplest
  2370.      approach is to print them, when *print-readably* is not nil, as if
  2371.      *print-level* and *print-length* were nil, regardless of their actual
  2372.      values.
  2373.  
  2374. [change_end]
  2375.  
  2376. [old_change_begin]
  2377.  
  2378. Bit-vectors
  2379.      A bit-vector is printed as #* followed by the bits of the bit-vector in
  2380.      order. If *print-array* is nil, however, then the bit-vector is printed in
  2381.      a format (using #<) that is concise but not readable. If the bit-vector
  2382.      has a fill pointer, then only those bits below the fill pointer are
  2383.      printed.
  2384.  
  2385. [old_change_end]
  2386.  
  2387. [change_begin]
  2388.  
  2389.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2390.      is not nil then every object must be printed in a readable form,
  2391.      regardless of other printer control variables. For bit-vectors, the
  2392.      simplest approach is to print them, when *print-readably* is not nil, as
  2393.      if *print-array* were not nil, regardless of the actual value of
  2394.      *print-array*.
  2395.  
  2396. [change_end]
  2397.  
  2398. Vectors
  2399.      Any vector other than a string or bit-vector is printed using
  2400.      general-vector syntax; this means that information about specialized
  2401.      vector representations will be lost. The printed representation of a
  2402.      zero-length vector is #(). The printed representation of a non-zero-length
  2403.      vector begins with #(. Following that, the first element of the vector is
  2404.      printed. If there are any other elements, they are printed in turn, with a
  2405.      space printed before each additional element. A close parenthesis after
  2406.      the last element terminates the printed representation of the vector.
  2407.  
  2408. [old_change_begin]
  2409.  
  2410.      The printing of vectors is affected by the variables *print-level* and
  2411.      *print-length*. If the vector has a fill pointer, then only those elements
  2412.      below the fill pointer are printed.
  2413.  
  2414.      If *print-array* is nil, however, then the vector is not printed as
  2415.      described above, but in a format (using #<) that is concise but not
  2416.      readable.
  2417.  
  2418. [old_change_end]
  2419.  
  2420. [change_begin]
  2421.  
  2422.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2423.      is not nil then every object must be printed in a readable form,
  2424.      regardless of other printer control variables. For vectors, the simplest
  2425.      approach is to print them, when *print-readably* is not nil, as if
  2426.      *print-level* and *print-length* were nil and *print-array* were not nil,
  2427.      regardless of their actual values.
  2428.  
  2429. [change_end]
  2430.  
  2431. Arrays
  2432.      Normally any array other than a vector is printed using #nA format. Let n
  2433.      be the rank of the array. Then # is printed, then n as a decimal integer,
  2434.      then A, then n open parentheses. Next the elements are scanned in
  2435.      row-major order. Imagine the array indices being enumerated in odometer
  2436.      fashion, recalling that the dimensions are numbered from 0 to n-1. Every
  2437.      time the index for dimension j is incremented, the following actions are
  2438.      taken:
  2439.  
  2440.        1.  If j<n-1, then print a close parenthesis.
  2441.  
  2442.        2.  If incrementing the index for dimension j caused it to equal
  2443.           dimension j, reset that index to zero and increment dimension j-1
  2444.           (thereby performing these three steps recursively), unless j=0, in
  2445.           which case simply terminate the entire algorithm. If incrementing the
  2446.           index for dimension j did not cause it to equal dimension j, then
  2447.           print a space.
  2448.  
  2449.        3.  If j<n-1, then print an open parenthesis.
  2450.  
  2451.      This causes the contents to be printed in a format suitable for use as the
  2452.      :initial-contents argument to make-array.
  2453.  
  2454. [old_change_begin]
  2455.  
  2456.      The lists effectively printed by this procedure are subject to truncation
  2457.      by *print-level* and *print-length*.
  2458.  
  2459. [old_change_end]
  2460.  
  2461.      If the array is of a specialized type, containing bits or
  2462.      string-characters, then the innermost lists generated by the algorithm
  2463.      given above may instead be printed using bit-vector or string syntax,
  2464.      provided that these innermost lists would not be subject to truncation by
  2465.      *print-length*. For example, a 3-by-2-by-4 array of string-characters that
  2466.      would ordinarily be printed as
  2467.  
  2468.      #3A(((#\s #\t #\o #\p) (#\s #\p #\o #\t))
  2469.          ((#\p #\o #\s #\t) (#\p #\o #\t #\s))
  2470.          ((#\t #\o #\p #\s) (#\o #\p #\t #\s)))
  2471.  
  2472.      may instead be printed more concisely as
  2473.  
  2474.      #3A(("stop" "spot") ("post" "pots") ("tops" "opts"))
  2475.  
  2476. [old_change_begin]
  2477.  
  2478.      If *print-array* is nil, then the array is printed in a format (using #<)
  2479.      that is concise but not readable.
  2480.  
  2481. [old_change_end]
  2482.  
  2483. [change_begin]
  2484.  
  2485.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2486.      is not nil then every object must be printed in a readable form,
  2487.      regardless of other printer control variables. For arrays, the simplest
  2488.      approach is to print them, when *print-readably* is not nil, as if
  2489.      *print-level* and *print-length* were nil and *print-array* were not nil,
  2490.      regardless of their actual values.
  2491.  
  2492. [change_end]
  2493.  
  2494. Random-states
  2495.      Common Lisp does not specify a specific syntax for printing objects of
  2496.      type random-state. However, every implementation must arrange to print a
  2497.      random-state object in such a way that, within the same implementation of
  2498.      Common Lisp, the function read can construct from the printed
  2499.      representation a copy of the random-state object as if the copy had been
  2500.      made by make-random-state.
  2501.  
  2502. [old_change_begin]
  2503.  
  2504. Pathnames
  2505.      Common Lisp does not specify a specific syntax for printing objects of
  2506.      type pathname. However, every implementation must arrange to print a
  2507.      pathname in such a way that, within the same implementation of Common
  2508.      Lisp, the function read can construct from the printed representation an
  2509.      equivalent instance of the pathname object.
  2510.  
  2511. [old_change_end]
  2512.  
  2513. [change_begin]
  2514.  
  2515.      X3J13 voted in June 1989 (PATHNAME-PRINT-READ)   to specify that if
  2516.      *print-escape* is true, a pathname should be printed by write as #P"..."
  2517.      where "..." is the namestring representation of the pathname. If
  2518.      *print-escape* is false, write prints a pathname by printing its
  2519.      namestring (presumably without escape characters or surrounding double
  2520.      quotes).
  2521.  
  2522.      X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably*
  2523.      is not nil then every object must be printed in a readable form,
  2524.      regardless of other printer control variables. For pathnames, the simplest
  2525.      approach is to print them, when *print-readably* is not nil, as if
  2526.      *print-escape* were nil, regardless of its actual value.
  2527.  
  2528. [change_end]
  2529.  
  2530. Structures defined by defstruct are printed under the control of the
  2531. user-specified :print-function option to defstruct. If the user does not
  2532. provide a printing function explicitly, then a default printing function is
  2533. supplied that prints the structure using #S syntax (see section 22.1.4).
  2534.  
  2535. [old_change_begin]
  2536. Any other types are printed in an implementation-dependent manner. It is
  2537. recommended that printed representations of all such objects begin with the
  2538. characters #< and end with > so that the reader will catch such objects and not
  2539. permit them to be read under normal circumstances. It is specifically and
  2540. purposely not required that a Common Lisp implementation be able to print an
  2541. object of type hash-table, readtable, package, stream, or function in a way
  2542. that can be read back in successfully by read; the use of #< syntax is
  2543. especially recommended for the printing of such objects.
  2544. [old_change_end]
  2545.  
  2546. [change_begin]
  2547. X3J13 voted in June 1989 (DATA-IO)   to specify that if *print-readably* is not
  2548. nil then every object must be printed in a readable form, regardless of the
  2549. values of other printer control variables; if this is not possible, then an
  2550. error of type print-not-readable must be signaled to avoid printing an
  2551. unreadable syntax such as #<...>.
  2552.  
  2553. X3J13 voted in June 1989 (DATA-IO)   to add print-unreadable-object, a macro
  2554. that prints an object using #<...> syntax and also takes care of checking the
  2555. variable *print-readably*.
  2556. [change_end]
  2557.  
  2558. When debugging or when frequently dealing with large or deep objects at top
  2559. level, the user may wish to restrict the printer from printing large amounts of
  2560. information. The variables *print-level* and *print-length* allow the user to
  2561. control how deep the printer will print and how many elements at a given level
  2562. the printer will print. Thus the user can see enough of the object to identify
  2563. it without having to wade through the entire expression.
  2564.  
  2565. [change_begin]
  2566.  
  2567. [Variable]
  2568. *print-readably*
  2569.  
  2570. The default value of *print-readably* is nil. If *print-readably* is true, then
  2571. printing any object must either produce a printed representation that the
  2572. reader will accept or signal an error. If printing is successful, the reader
  2573. will, on reading the printed representation, produce an object that is
  2574. ``similar as a constant'' (see section 25.1.4) to the object that was printed.
  2575.  
  2576. If *print-readably* is true and printing a readable printed representation is
  2577. not possible, the printer signals an error of type print-not-readable rather
  2578. than using an unreadable syntax such as #<. The printed representation produced
  2579. when *print-readably* is true might or might not be the same as the printed
  2580. representation produced when *print-readably* is false.
  2581.  
  2582. If *print-readably* is true and another printer control variable (such as
  2583. *print-length*, *print-level*, *print-escape*, *print-gensym*, *print-array*,
  2584. or an implementation-defined printer control variable) would cause the
  2585. preceding requirements to be violated, that other printer control variable is
  2586. ignored.
  2587.  
  2588. The printing of interned symbols is not affected by *print-readably*.
  2589.  
  2590. Note that the ``similar as a constant'' rule for readable printing implies that
  2591. #A or #( syntax cannot be used for arrays of element-type other than t. An
  2592. implementation will have to use another syntax or signal a print-not-readable
  2593. error. A print-not-readable error will not be signaled for strings or
  2594. bit-vectors.
  2595.  
  2596. All methods for print-object must obey *print-readably*. This rule applies to
  2597. both user-defined methods and implementation-defined methods.
  2598.  
  2599. The reader control variable *read-eval* also affects printing. If *read-eval*
  2600. is false and *print-readably* is true, any print-object method that would
  2601. otherwise output a #. reader macro must either output something different or
  2602. signal an error of type print-not-readable.
  2603.  
  2604. Readable printing of structures and objects of type standard-object is
  2605. controlled by their print-object methods, not by their make-load-form methods.
  2606. ``Similarity as a constant'' for these objects is application-dependent and
  2607. hence is defined to be whatever these methods do.
  2608.  
  2609. *print-readably* allows errors involving data with no readable printed
  2610. representation to be detected when writing the file rather than later on when
  2611. the file is read.
  2612.  
  2613. *print-readably* is more rigorous than *print-escape*; output printed with
  2614. escapes must be merely generally recognizable by humans, with a good chance of
  2615. being recognizable by computers, whereas output printed readably must be
  2616. reliably recognizable by computers.
  2617. [change_end]
  2618.  
  2619. [Variable]
  2620. *print-escape*
  2621.  
  2622. When this flag is nil, then escape characters are not output when an expression
  2623. is printed. In particular, a symbol is printed by simply printing the
  2624. characters of its print name. The function princ effectively binds
  2625. *print-escape* to nil.
  2626.  
  2627. When this flag is not nil, then an attempt is made to print an expression in
  2628. such a way that it can be read again to produce an equal structure. The
  2629. function prin1 effectively binds *print-escape* to t. The initial value of this
  2630. variable is t.
  2631.  
  2632. -------------------------------------------------------------------------------
  2633. Compatibility note: *print-escape* controls what was called slashification in
  2634. MacLisp.
  2635. -------------------------------------------------------------------------------
  2636.  
  2637. [Variable]
  2638. *print-pretty*
  2639.  
  2640. When this flag is nil, then only a small amount of whitespace is output when
  2641. printing an expression.
  2642.  
  2643. When this flag is not nil, then the printer will endeavor to insert extra
  2644. whitespace where appropriate to make the expression more readable. A few other
  2645. simple changes may be made, such as printing 'foo instead of (quote foo).
  2646.  
  2647. The initial value of *print-pretty* is implementation-dependent.
  2648.  
  2649. [change_begin]
  2650. X3J13 voted in January 1989 (PRETTY-PRINT-INTERFACE)   to adopt a facility for
  2651. user-controlled pretty printing in Common Lisp (see chapter 27).
  2652. [change_end]
  2653.  
  2654. [Variable]
  2655. *print-circle*
  2656.  
  2657. When this flag is nil (the default), then the printing process proceeds by
  2658. recursive descent; an attempt to print a circular structure may lead to looping
  2659. behavior and failure to terminate.
  2660.  
  2661. [old_change_begin]
  2662. When this flag is not nil, then the printer will endeavor to detect cycles in
  2663. the structure to be printed, and to use #n= and #n# syntax to indicate the
  2664. circularities.
  2665. [old_change_end]
  2666.  
  2667. [change_begin]
  2668. X3J13 voted in June 1989 (PRINT-CIRCLE-SHARED)   to specify that if
  2669. *print-circle* is true, the printer is required to detect not only cycles but
  2670. shared substructure, indicating both through the use of #n= and #n# syntax. As
  2671. an example, under the specification of the first edition
  2672.  
  2673. (print '(#1=(a #1#) #1#))
  2674.  
  2675. might legitimately print (#1=(A #1#) #1#) or (#1=(A #1#) #2=(A #2#)); the vote
  2676. specifies that the first form is required.
  2677.  
  2678. X3J13 voted in January 1989 (PRINT-CIRCLE-STRUCTURE)   to specify that
  2679. user-defined printing functions for the defstruct :print-function option, as
  2680. well as user-defined methods for the CLOS generic function print-object, may
  2681. print objects to the supplied stream using write, print1, princ, format, or
  2682. print-object and expect circularities to be detected and printed using #n#
  2683. syntax (when *print-circle* is non-nil, of course).
  2684.  
  2685. It seems to me that the same ought to apply to abbreviation as controlled by
  2686. *print-level* and *print-length*, but that was not addressed by this vote.
  2687. [change_end]
  2688.  
  2689. [Variable]
  2690. *print-base*
  2691.  
  2692. The value of *print-base* determines in what radix the printer will print
  2693. rationals. This may be any integer from 2 to 36, inclusive; the default value
  2694. is 10 (decimal radix). For radices above 10, letters of the alphabet are used
  2695. to represent digits above 9.
  2696.  
  2697. -------------------------------------------------------------------------------
  2698. Compatibility note:MacLisp calls this variable base, and its default value is
  2699. 8, not 10.
  2700.  
  2701. In both MacLisp and Common Lisp, floating-point numbers are always printed in
  2702. decimal, no matter what the value of *print-base*.
  2703. -------------------------------------------------------------------------------
  2704.  
  2705. [Variable]
  2706. *print-radix*
  2707.  
  2708. If the variable *print-radix* is non-nil, the printer will print a radix
  2709. specifier to indicate the radix in which it is printing a rational number. To
  2710. prevent confusion of the letter O with the digit 0, and of the letter B with
  2711. the digit 8, the radix specifier is always printed using lowercase letters. For
  2712. example, if the current base is twenty-four (decimal), the decimal integer
  2713. twenty-three would print as #24rN. If *print-base* is 2, 8, or 16, then the
  2714. radix specifier used is #b, #o, or #x. For integers, base ten is indicated by a
  2715. trailing decimal point instead of a leading radix specifier; for ratios,
  2716. however, #10r is used. The default value of *print-radix* is nil.
  2717.  
  2718. [Variable]
  2719. *print-case*
  2720.  
  2721. The read function normally converts lowercase characters appearing in symbols
  2722. to corresponding uppercase characters, so that internally print names normally
  2723. contain only uppercase characters. However, users may prefer to see output
  2724. using lowercase letters or letters of mixed case. This variable controls the
  2725. case (upper, lower, or mixed) in which to print any uppercase characters in the
  2726. names of symbols when vertical-bar syntax is not used. The value of
  2727. *print-case* should be one of the keywords :upcase, :downcase, or :capitalize;
  2728. the initial value is :upcase.
  2729.  
  2730. Lowercase characters in the internal print name are always printed in
  2731. lowercase, and are preceded by a single escape character or enclosed by
  2732. multiple escape characters. Uppercase characters in the internal print name are
  2733. printed in uppercase, in lowercase, or in mixed case so as to capitalize words,
  2734. according to the value of *print-case*. The convention for what constitutes a
  2735. ``word'' is the same as for the function string-capitalize.
  2736.  
  2737. [change_begin]
  2738. X3J13 voted in June 1989 (PRINT-CASE-PRINT-ESCAPE-INTERACTION)   to clarify the
  2739. interaction of *print-case* with *print-escape*. When *print-escape* is nil,
  2740. *print-case* determines the case in which to print all uppercase characters in
  2741. the print name of the symbol. When *print-escape* is not nil, the
  2742. implementation has some freedom as to which characters will be printed so as to
  2743. appear in an ``escape context'' (after an escape character, typically , or
  2744. between multiple escape characters, typically |); *print-case* determines the
  2745. case in which to print all uppercase characters that will not appear in an
  2746. escape context. For example, when the value of *print-case* is :upcase, an
  2747. implementation might choose to print the symbol whose print name is "(S)HE" as
  2748. (S )HE or as |(S)HE|, among other possibilities. When the value of *print-case*
  2749. is :downcase, the corresponding output should be (s )he or |(S)HE|,
  2750. respectively.
  2751.  
  2752. Consider the following test code. (For the sake of this example assume that
  2753. readtable-case is :upcase in the current readtable; this is discussed further
  2754. below.)
  2755.  
  2756. (let ((tabwidth 11))
  2757.   (dolist (sym '(|x| |FoObAr| |fOo|))
  2758.     (let ((tabstop -1))
  2759.       (format t "~&")
  2760.       (dolist (escape '(t nil))
  2761.         (dolist (case '(:upcase :downcase :capitalize))
  2762.           (format t "~VT" (* (incf tabstop) tabwidth))
  2763.           (write sym :escape escape :case case)))))
  2764.   (format t "~%"))
  2765.  
  2766. An implementation that leans heavily on multiple-escape characters (vertical
  2767. bars) might produce the following output:
  2768.  
  2769. |x|        |x|        |x|        x          x          x
  2770. |FoObAr|   |FoObAr|   |FoObAr|   FoObAr     foobar     Foobar
  2771. |fOo|      |fOo|      |fOo|      fOo        foo        foo
  2772.  
  2773. An implementation that leans heavily on single-escape characters (backslashes)
  2774. might produce the following output:
  2775.  
  2776. \x         \x         \x         x          x          x
  2777. F\oO\bA\r  f\oo\ba\r  F\oo\ba\r  FoObAr     foobar     Foobar
  2778. \fO\o      \fo\o      \fo\o      fOo        foo        foo
  2779.  
  2780. These examples are not exhaustive; output using both kinds of escape characters
  2781. (for example, |FoO|\bA\r) is permissible (though ugly).
  2782.  
  2783. X3J13 voted in June 1989 (READ-CASE-SENSITIVITY)   to add a new readtable-case
  2784. slot to readtables to control automatic case conversion during the reading of
  2785. symbols. The value of readtable-case in the current readtable also affects the
  2786. printing of unescaped letters (letters appearing in an escape context are
  2787. always printed in their own case).
  2788.  
  2789.    *  If readtable-case is :upcase, unescaped uppercase letters are printed in
  2790.      the case specified by *print-case* and unescaped lowercase letters are
  2791.      printed in their own case. (If *print-escape* is non-nil, all lowercase
  2792.      letters will necessarily be escaped.)
  2793.  
  2794.    *  If readtable-case is :downcase, unescaped lowercase letters are printed
  2795.      in the case specified by *print-case* and unescaped uppercase letters are
  2796.      printed in their own case. (If *print-escape* is non-nil, all uppercase
  2797.      letters will necessarily be escaped.)
  2798.  
  2799.    *  If readtable-case is :preserve, all unescaped letters are printed in
  2800.      their own case, regardless of the value of *print-case*. There is no need
  2801.      to escape any letters, even if *print-escape* is non-nil, though the X3J13
  2802.      vote did not prohibit escaping letters in this situation.
  2803.  
  2804.    *  If readtable-case is :invert, and if all unescaped letters are of the
  2805.      same case, then the case of all the unescaped letters is inverted; but if
  2806.      the unescaped letters are not all of the same case then each is printed in
  2807.      its own case. (Thus :invert does not always invert the case; the inversion
  2808.      is conditional.) There is no need to escape any letters, even if
  2809.      *print-escape* is non-nil, though the X3J13 vote did not prohibit escaping
  2810.      letters in this situation.
  2811.  
  2812. Consider the following code.
  2813.  
  2814. ;;; Generate a table illustrating READTABLE-CASE and *PRINT-CASE*.
  2815.  
  2816. (let ((*readtable* (copy-readtable nil))
  2817.       (*print-case* *print-case*))
  2818.   (format t "READTABLE-CASE *PRINT-CASE*  Symbol-name  Output~
  2819.            ~%------------------------------------------------~
  2820.            ~%")
  2821.   (dolist (readtable-case '(:upcase :downcase :preserve :invert))
  2822.     (setf (readtable-case *readtable*) readtable-case)
  2823.     (dolist (print-case '(:upcase :downcase :capitalize))
  2824.       (dolist (sym '(|ZEBRA| |Zebra| |zebra|))
  2825.         (setq *print-case* print-case)
  2826.         (format t ":~A~15T:~A~29T~A~42T~A~%"
  2827.                   (string-upcase readtable-case)
  2828.                   (string-upcase print-case)
  2829.                   (symbol-name sym)
  2830.                   (prin1-to-string sym)))))))
  2831.  
  2832. Note that the call to prin1-to-string (the last argument in the call to format
  2833. that is within the nested loops) effectively uses a non-nil value for
  2834. *print-escape*.
  2835.  
  2836. Assuming an implementation that uses vertical bars around a symbol name if any
  2837. characters need escaping, the output from this test code should be
  2838.  
  2839. READTABLE-CASE *PRINT-CASE*  Symbol-name  Output
  2840. ------------------------------------------------
  2841. :UPCASE        :UPCASE       ZEBRA        ZEBRA
  2842. :UPCASE        :UPCASE       Zebra        |Zebra|
  2843. :UPCASE        :UPCASE       zebra        |zebra|
  2844. :UPCASE        :DOWNCASE     ZEBRA        zebra
  2845. :UPCASE        :DOWNCASE     Zebra        |Zebra|
  2846. :UPCASE        :DOWNCASE     zebra        |zebra|
  2847. :UPCASE        :CAPITALIZE   ZEBRA        Zebra
  2848. :UPCASE        :CAPITALIZE   Zebra        |Zebra|
  2849. :UPCASE        :CAPITALIZE   zebra        |zebra|
  2850. :DOWNCASE      :UPCASE       ZEBRA        |ZEBRA|
  2851. :DOWNCASE      :UPCASE       Zebra        |Zebra|
  2852. :DOWNCASE      :UPCASE       zebra        ZEBRA
  2853. :DOWNCASE      :DOWNCASE     ZEBRA        |ZEBRA|
  2854. :DOWNCASE      :DOWNCASE     Zebra        |Zebra|
  2855. :DOWNCASE      :DOWNCASE     zebra        zebra
  2856. :DOWNCASE      :CAPITALIZE   ZEBRA        |ZEBRA|
  2857. :DOWNCASE      :CAPITALIZE   Zebra        |Zebra|
  2858. :DOWNCASE      :CAPITALIZE   zebra        Zebra
  2859. :PRESERVE      :UPCASE       ZEBRA        ZEBRA
  2860. :PRESERVE      :UPCASE       Zebra        Zebra
  2861. :PRESERVE      :UPCASE       zebra        zebra
  2862. :PRESERVE      :DOWNCASE     ZEBRA        ZEBRA
  2863. :PRESERVE      :DOWNCASE     Zebra        Zebra
  2864. :PRESERVE      :DOWNCASE     zebra        zebra
  2865. :PRESERVE      :CAPITALIZE   ZEBRA        ZEBRA
  2866. :PRESERVE      :CAPITALIZE   Zebra        Zebra
  2867. :PRESERVE      :CAPITALIZE   zebra        zebra
  2868. :INVERT        :UPCASE       ZEBRA        zebra
  2869. :INVERT        :UPCASE       Zebra        Zebra
  2870. :INVERT        :UPCASE       zebra        ZEBRA
  2871. :INVERT        :DOWNCASE     ZEBRA        zebra
  2872. :INVERT        :DOWNCASE     Zebra        Zebra
  2873. :INVERT        :DOWNCASE     zebra        ZEBRA
  2874. :INVERT        :CAPITALIZE   ZEBRA        zebra
  2875. :INVERT        :CAPITALIZE   Zebra        Zebra
  2876. :INVERT        :CAPITALIZE   zebra        ZEBRA
  2877.  
  2878. This illustrates all combinations for readtable-case and *print-case*.
  2879.  
  2880. [change_end]
  2881.  
  2882. [Variable]
  2883. *print-gensym*
  2884.  
  2885. The *print-gensym* variable controls whether the prefix #: is printed before
  2886. symbols that have no home package. The prefix is printed if the variable is not
  2887. nil. The initial value of *print-gensym* is t.
  2888.  
  2889. [Variable]
  2890. *print-level* 
  2891. *print-length* 
  2892.  
  2893. The *print-level* variable controls how many levels deep a nested data object
  2894. will print. If *print-level* is nil (the initial value), then no control is
  2895. exercised. Otherwise, the value should be an integer, indicating the maximum
  2896. level to be printed. An object to be printed is at level 0; its components (as
  2897. of a list or vector) are at level 1; and so on. If an object to be recursively
  2898. printed has components and is at a level equal to or greater than the value of
  2899. *print-level*, then the object is printed as simply #.
  2900.  
  2901. The *print-length* variable controls how many elements at a given level are
  2902. printed. A value of nil (the initial value) indicates that there be no limit to
  2903. the number of components printed. Otherwise, the value of *print-length* should
  2904. be an integer. Should the number of elements of a data object exceed the value
  2905. *print-length*, the printer will print three dots, ..., in place of those
  2906. elements beyond the number specified by *print-length*. (In the case of a
  2907. dotted list, if the list contains exactly as many elements as the value of
  2908. *print-length*, and in addition has the non-null atom terminating it, that
  2909. terminating atom is printed rather than the three dots.)
  2910.  
  2911. *print-level* and *print-length* affect the printing not only of lists but also
  2912. of vectors, arrays, and any other object printed with a list-like syntax. They
  2913. do not affect the printing of symbols, strings, and bit-vectors.
  2914.  
  2915. The Lisp reader will normally signal an error when reading an expression that
  2916. has been abbreviated because of level or length limits. This signal is given
  2917. because the # dispatch character normally signals an error when followed by
  2918. whitespace or ), and because ... is defined to be an illegal token, as are all
  2919. tokens consisting entirely of periods (other than the single dot used in dot
  2920. notation).
  2921.  
  2922. As an example, table 22-6 shows the ways the object
  2923.  
  2924. (if (member x y) (+ (car x) 3) '(foo . #(a b c d "Baz")))
  2925.  
  2926. would be printed for various values of *print-level* (in the column labeled v)
  2927. and *print-length* (in the column labeled n).
  2928.  
  2929.  
  2930. ----------------------------------------------------------------
  2931. Table 22-6: Examples of Print Level and Print Length Abbreviation
  2932.  
  2933. v  n  Output
  2934. ======================================================
  2935. 0  1  #
  2936. 1  1  (if ...)
  2937. 1  2  (if # ...)
  2938. 1  3  (if # # ...)
  2939. 1  4  (if # # #)
  2940. 2  1  (if ...)
  2941. 2  2  (if (member x ...) ...)
  2942. 2  3  (if (member x y) (+ # 3) ...)
  2943. 3  2  (if (member x ...) ...)
  2944. 3  3  (if (member x y) (+ (car x) 3) ...)
  2945. 3  4  (if (member x y) (+ (car x) 3) '(foo . #(a b c d ...)))
  2946. 3  5  (if (member x y) (+ (car x) 3) '(foo . #(a b c d "Baz")))
  2947. ======================================================
  2948. ----------------------------------------------------------------
  2949.  
  2950. [Variable]
  2951. *print-array*
  2952.  
  2953. If *print-array* is nil, then the contents of arrays other than strings are
  2954. never printed. Instead, arrays are printed in a concise form (using #<) that
  2955. gives enough information for the user to be able to identify the array but does
  2956. not include the entire array contents. If *print-array* is not nil, non-string
  2957. arrays are printed using #(, #*, or #nA syntax.
  2958.  
  2959. [change_begin]
  2960. Notice of correction. In the first edition, the preceding paragraph mentioned
  2961. the nonexistent variable print-array instead of *print-array*.
  2962. [change_end]
  2963.  
  2964. The initial value of *print-array* is implementation-dependent.
  2965.  
  2966. [change_begin]
  2967.  
  2968. [Macro]
  2969. with-standard-io-syntax {declaration}* {form}*
  2970.  
  2971. X3J13 voted in June 1989 (DATA-IO)   to add the macro with-standard-io-syntax.
  2972. Within the dynamic extent of the body, all reader/printer controlvariables,
  2973. including any implementation-defined ones not specified byCommon Lisp, are
  2974. bound to values that produce standard read/printbehavior. Table 22-7 shows the
  2975. values to which standard Common Lisp variables are bound.
  2976.  
  2977. The values returned by with-standard-io-syntax are the values of the last body
  2978. form, or nil if there are no body forms.
  2979.  
  2980. The intent is that a pair of executions, as shown in the following example,
  2981. should provide reasonable reliable communication of data from one Lisp process
  2982. to another:
  2983.  
  2984. ;;; Write DATA to a file.
  2985. (with-open-file (file pathname :direction :output)
  2986.   (with-standard-io-syntax
  2987.     (print data file)))
  2988.  
  2989. ;;; ...  Later, in another Lisp:
  2990. (with-open-file (file pathname :direction :input)
  2991.   (with-standard-io-syntax
  2992.     (setq data (read file))))
  2993.  
  2994. Using with-standard-io-syntax to bind all the variables, instead of using let
  2995. and explicit bindings, ensures that nothing is overlooked and avoids problems
  2996. with implementation-defined reader/printer control variables. If the user
  2997. wishes to use a non-standard value for some variable, such as *package* or
  2998. *read-eval*, it can be bound by let inside the body of with-standard-io-syntax.
  2999. For example:
  3000.  
  3001. ;;; Write DATA to a file.  Forbid use of #. syntax.
  3002. (with-open-file (file pathname :direction :output)
  3003.   (let ((*read-eval* nil))
  3004.     (with-standard-io-syntax
  3005.       (print data file))))
  3006.  
  3007. ;;; Read DATA from a file.  Forbid use of #. syntax.
  3008. (with-open-file (file pathname :direction :input)
  3009.   (let ((*read-eval* nil))
  3010.     (with-standard-io-syntax
  3011.       (setq data (read file)))))
  3012.  
  3013. Similarly, a user who dislikes the arbitrary choice of values for
  3014. *print-circle* and *print-pretty* can bind these variables to other values
  3015. inside the body.
  3016.  
  3017. The X3J13 vote left it unclear whether with-standard-io-syntax permits
  3018. declarations to appear before the body of the macro call. I believe that was
  3019. the intent, and this is reflected in the syntax shown above; but this is only
  3020. my interpretation.
  3021.  
  3022.  
  3023. ----------------------------------------------------------------
  3024. Table 22-7: Standard Bindings for I/O Control Variables
  3025.  
  3026. Variable                     Value
  3027. ===========================================================
  3028. *package*                    the common-lisp-user package
  3029. *print-array*                t
  3030. *print-base*                 10
  3031. *print-case*                 :upcase
  3032. *print-circle*               nil
  3033. *print-escape*               t
  3034. *print-gensym*               t
  3035. *print-length*               nil
  3036. *print-level*                nil
  3037. *print-lines*                nil *
  3038. *print-miser-width*          nil *
  3039. *print-pprint-dispatch*      nil *
  3040. *print-pretty*               nil
  3041. *print-radix*                nil
  3042. *print-readably*             t
  3043. *print-right-margin*         nil *
  3044. *read-base*                  10
  3045. *read-default-float-format*  single-float
  3046. *read-eval*                  t
  3047. *read-suppress*              nil
  3048. *readtable*                  the standard readtable
  3049.  
  3050. * X3J13 voted in June 1989 (PRETTY-PRINT-INTERFACE)
  3051. to introduce the printer control variables *print-right-margin*,
  3052. *print-miser-width*, *print-lines*, and
  3053. *print-pprint-dispatch* (see section 27.2) but did not
  3054. specify the values to which with-standard-io-syntax should
  3055. bind them.  I recommend that all four should be bound to nil.
  3056. ----------------------------------------------------------------
  3057.  
  3058. [change_end]
  3059.  
  3060. -------------------------------------------------------------------------------
  3061.  
  3062. 22.2. Input Functions
  3063.  
  3064. The input functions are divided into two groups: those that operate on streams
  3065. of characters and those that operate on streams of binary data.
  3066.  
  3067. -------------------------------------------------------------------------------
  3068.  
  3069.    *  Input from Character Streams
  3070.    *  Input from Binary Streams
  3071.  
  3072. -------------------------------------------------------------------------------
  3073.  
  3074. 22.2.1. Input from Character Streams
  3075.  
  3076. Many character input functions take optional arguments called input-stream,
  3077. eof-error-p, and eof-value. The input-stream argument is the stream from which
  3078. to obtain input; if unsupplied or nil it defaults to the value of the special
  3079. variable *standard-input*. One may also specify t as a stream, meaning the
  3080. value of the special variable *terminal-io*.
  3081.  
  3082. The eof-error-p argument controls what happens if input is from a file (or any
  3083. other input source that has a definite end) and the end of the file is reached.
  3084. If eof-error-p is true (the default), an error will be signaled at end of file.
  3085. If it is false, then no error is signaled, and instead the function returns
  3086. eof-value.
  3087.  
  3088. [change_begin]
  3089. X3J13 voted in January 1989 (ARGUMENTS-UNDERSPECIFIED)   to clarify that an
  3090. eof-value argument may be any Lisp datum whatsoever.
  3091. [change_end]
  3092.  
  3093. Functions such as read that read the representation of an object rather than a
  3094. single character will always signal an error, regardless of eof-error-p, if the
  3095. file ends in the middle of an object representation. For example, if a file
  3096. does not contain enough right parentheses to balance the left parentheses in
  3097. it, read will complain. If a file ends in a symbol or a number immediately
  3098. followed by end-of-file, read will read the symbol or number successfully and
  3099. when called again will see the end-of-file and only then act according to
  3100. eof-error-p. Similarly, the function read-line will successfully read the last
  3101. line of a file even if that line is terminated by end-of-file rather than the
  3102. newline character. If a file contains ignorable text at the end, such as blank
  3103. lines and comments, read will not consider it to end in the middle of an
  3104. object. Thus an eof-error-p argument controls what happens when the file ends
  3105. between objects.
  3106.  
  3107. Many input functions also take an argument called recursive-p. If specified and
  3108. not nil, this argument specifies that this call is not a ``top-level'' call to
  3109. read but an imbedded call, typically from the function for a macro character.
  3110. It is important to distinguish such recursive calls for three reasons.
  3111.  
  3112. First, a top-level call establishes the context within which the #n= and #n#
  3113. syntax is scoped. Consider, for example, the expression
  3114.  
  3115. (cons '#3=(p q r) '(x y . #3#))
  3116.  
  3117. If the single-quote macro character were defined in this way:
  3118.  
  3119. (set-macro-character #\'
  3120.                      #'(lambda (stream char)
  3121.                          (declare (ignore char))
  3122.                          (list 'quote (read stream))))
  3123.  
  3124. then the expression could not be read properly, because there would be no way
  3125. to know when read is called recursively by the first occurrence of ' that the
  3126. label #3= would be referred to later in the containing expression. There would
  3127. be no way to know because read could not determine that it was called by a
  3128. macro-character function rather than from ``top level.'' The correct way to
  3129. define the single quote macro character uses the recursive-p argument:
  3130.  
  3131. (set-macro-character #\'
  3132.                      #'(lambda (stream char)
  3133.                          (declare (ignore char))
  3134.                          (list 'quote (read stream t nil t))))
  3135.  
  3136. Second, a recursive call does not alter whether the reading process is to
  3137. preserve whitespace or not (as determined by whether the top-level call was to
  3138. read or read-preserving-whitespace). Suppose again that the single quote had
  3139. the first, incorrect, macro-character definition shown above. Then a call to
  3140. read-preserving-whitespace that read the expression 'foo would fail to preserve
  3141. the space character following the symbol foo because the single-quote
  3142. macro-character function calls read, not read-preserving-whitespace, to read
  3143. the following expression (in this case foo). The correct definition, which
  3144. passes the value t for the recursive-p argument to read, allows the top-level
  3145. call to determine whether whitespace is preserved.
  3146.  
  3147. Third, when end-of-file is encountered and the eof-error-p argument is not nil,
  3148. the kind of error that is signaled may depend on the value of recursive-p. If
  3149. recursive-p is not nil, then the end-of-file is deemed to have occurred within
  3150. the middle of a printed representation; if recursive-p is nil, then the
  3151. end-of-file may be deemed to have occurred between objects rather than within
  3152. the middle of one.
  3153.  
  3154. [Function]
  3155. read &optional input-stream eof-error-p eof-value recursive-p
  3156.  
  3157. read reads in the printed representation of a Lisp object from input-stream,
  3158. builds a corresponding Lisp object, and returns the object.
  3159.  
  3160. Note that when the variable *read-suppress* is not nil, then read reads in a
  3161. printed representation as best it can, but most of the work of interpreting the
  3162. representation is avoided (the intent being that the result is to be discarded
  3163. anyway). For example, all extended tokens produce the result nil regardless of
  3164. their syntax.
  3165.  
  3166. [Variable]
  3167. *read-default-float-format*
  3168.  
  3169. The value of this variable must be a type specifier symbol for a specific
  3170. floating-point format; these include short-float, single-float, double-float,
  3171. and long-float and may include implementation-specific types as well. The
  3172. default value is single-float.
  3173.  
  3174. *read-default-float-format* indicates the floating-point format to be used for
  3175. reading floating-point numbers that have no exponent marker or have e or E for
  3176. an exponent marker. (Other exponent markers explicitly prescribe the
  3177. floating-point format to be used.) The printer also uses this variable to guide
  3178. the choice of exponent markers when printing floating-point numbers.
  3179.  
  3180. [Function]
  3181. read-preserving-whitespace &optional in-stream eof-error-p eof-value
  3182. recursive-p
  3183.  
  3184. Certain printed representations given to read, notably those of symbols and
  3185. numbers, require a delimiting character after them. (Lists do not, because the
  3186. close parenthesis marks the end of the list.) Normally read will throw away the
  3187. delimiting character if it is a whitespace character; but read will preserve
  3188. the character (using unread-char) if it is syntactically meaningful, because it
  3189. may be the start of the next expression.
  3190.  
  3191. [change_begin]
  3192. X3J13 voted in January 1989 (PEEK-CHAR-READ-CHAR-ECHO)   to clarify the
  3193. interaction of unread-char with echo streams. These changes indirectly affect
  3194. the echoing behavior of read-preserving-whitespace.
  3195. [change_end]
  3196.  
  3197. The function read-preserving-whitespace is provided for some specialized
  3198. situations where it is desirable to determine precisely what character
  3199. terminated the extended token.
  3200.  
  3201. As an example, consider this macro-character definition:
  3202.  
  3203. (defun slash-reader (stream char)
  3204.   (declare (ignore char))
  3205.   (do ((path (list (read-preserving-whitespace stream))
  3206.              (cons (progn (read-char stream nil nil t)
  3207.                           (read-preserving-whitespace
  3208.                              stream))
  3209.                    path)))
  3210.       ((not (char= (peek-char nil stream nil nil t) #\/))
  3211.        (cons 'path (nreverse path)))))
  3212. (set-macro-character #\/ #'slash-reader)
  3213.  
  3214. (This is actually a rather dangerous definition to make because expressions
  3215. such as (/ x 3) will no longer be read properly. The ability to reprogram the
  3216. reader syntax is very powerful and must be used with caution. This redefinition
  3217. of / is shown here purely for the sake of example.)
  3218.  
  3219. Consider now calling read on this expression:
  3220.  
  3221. (zyedh /usr/games/zork /usr/games/boggle)
  3222.  
  3223. The / macro reads objects separated by more / characters; thus /usr/games/zork
  3224. is intended to be read as (path usr games zork). The entire example expression
  3225. should therefore be read as
  3226.  
  3227. (zyedh (path usr games zork) (path usr games boggle))
  3228.  
  3229. However, if read had been used instead of read-preserving-whitespace, then
  3230. after the reading of the symbol zork, the following space would be discarded;
  3231. the next call to peek-char would see the following /, and the loop would
  3232. continue, producing this interpretation:
  3233.  
  3234. (zyedh (path usr games zork usr games boggle))
  3235.  
  3236. On the other hand, there are times when whitespace should be discarded. If a
  3237. command interpreter takes single-character commands, but occasionally reads a
  3238. Lisp object, then if the whitespace after a symbol is not discarded it might be
  3239. interpreted as a command some time later after the symbol had been read.
  3240.  
  3241. Note that read-preserving-whitespace behaves exactly like read when the
  3242. recursive-p argument is not nil. The distinction is established only by calls
  3243. with recursive-p equal to nil or omitted.
  3244.  
  3245. [Function]
  3246. read-delimited-list char &optional input-stream recursive-p
  3247.  
  3248. This reads objects from stream until the next character after an object's
  3249. representation (ignoring whitespace characters and comments) is char. (The char
  3250. should not have whitespace syntax in the current readtable.) A list of the
  3251. objects read is returned.
  3252.  
  3253. To be more precise, read-delimited-list looks ahead at each step for the next
  3254. non-whitespace character and peeks at it as if with peek-char. If it is char,
  3255. then the character is consumed and the list of objects is returned. If it is a
  3256. constituent or escape character, then read is used to read an object, which is
  3257. added to the end of the list. If it is a macro character, the associated macro
  3258. function is called; if the function returns a value, that value is added to the
  3259. list. The peek-ahead process is then repeated.
  3260.  
  3261. [change_begin]
  3262. X3J13 voted in January 1989 (PEEK-CHAR-READ-CHAR-ECHO)   to clarify the
  3263. interaction of peek-char with echo streams. These changes indirectly affect the
  3264. echoing behavior of the function read-delimited-list.
  3265. [change_end]
  3266.  
  3267. This function is particularly useful for defining new macro characters. Usually
  3268. it is desirable for the terminating character char to be a terminating macro
  3269. character so that it may be used to delimit tokens; however,
  3270. read-delimited-list makes no attempt to alter the syntax specified for char by
  3271. the current readtable. The user must make any necessary changes to the
  3272. readtable syntax explicitly. The following example illustrates this.
  3273.  
  3274. Suppose you wanted #{a b c ... z} to be read as a list of all pairs of the
  3275. elements a, b, c, ..., z; for example:
  3276.  
  3277. #{p q z a}  reads as  ((p q) (p z) (p a) (q z) (q a) (z a))
  3278.  
  3279. This can be done by specifying a macro-character definition for #{ that does
  3280. two things: read in all the items up to the }, and construct the pairs.
  3281. read-delimited-list performs the first task.
  3282.  
  3283. [change_begin]
  3284. Note that mapcon allows the mapped function to examine the items of the list
  3285. after the current one, and that mapcon uses nconc, which is all right because
  3286. mapcar will produce fresh lists.
  3287. [change_end]
  3288.  
  3289. (defun |#{-reader| (stream char arg)
  3290.   (declare (ignore char arg))
  3291.   (mapcon #'(lambda (x)
  3292.               (mapcar #'(lambda (y) (list (car x) y)) (cdr x)))
  3293.           (read-delimited-list #\} stream t)))
  3294.  
  3295. (set-dispatch-macro-character #\# #\{ #'|#{-reader|)
  3296.  
  3297. (set-macro-character #\} (get-macro-character #\) nil))
  3298.  
  3299. (Note that t is specified for the recursive-p argument.)
  3300.  
  3301. It is necessary here to give a definition to the character } as well to prevent
  3302. it from being a constituent. If the line
  3303.  
  3304. (set-macro-character #\} (get-macro-character #\) nil))
  3305.  
  3306. shown above were not included, then the } in
  3307.  
  3308. #{p q z a}
  3309.  
  3310. would be considered a constituent character, part of the symbol named a}. One
  3311. could correct for this by putting a space before the }, but it is better simply
  3312. to use the call to set-macro-character.
  3313.  
  3314. Giving } the same definition as the standard definition of the character ) has
  3315. the twin benefit of making it terminate tokens for use with read-delimited-list
  3316. and also making it illegal for use in any other context (that is, attempting to
  3317. read a stray } will signal an error).
  3318.  
  3319. Note that read-delimited-list does not take an eof-error-p (or eof-value)
  3320. argument. The reason is that it is always an error to hit end-of-file during
  3321. the operation of read-delimited-list.
  3322.  
  3323. [Function]
  3324. read-line &optional input-stream eof-error-p eof-value recursive-p
  3325.  
  3326. read-line reads in a line of text terminated by a newline. It returns the line
  3327. as a character string (without the newline character). This function is usually
  3328. used to get a line of input from the user. A second returned value is a flag
  3329. that is false if the line was terminated normally, or true if end-of-file
  3330. terminated the (non-empty) line. If end-of-file is encountered immediately
  3331. (that is, appears to terminate an empty line), then end-of-file processing is
  3332. controlled in the usual way by the eof-error-p, eof-value, and recursive-p
  3333. arguments.
  3334.  
  3335. The corresponding output function is write-line.
  3336.  
  3337. [Function]
  3338. read-char &optional input-stream eof-error-p eof-value recursive-p
  3339.  
  3340. read-char inputs one character from input-stream and returns it as a character
  3341. object.
  3342.  
  3343. The corresponding output function is write-char.
  3344.  
  3345. [change_begin]
  3346. X3J13 voted in January 1989 (PEEK-CHAR-READ-CHAR-ECHO)   to clarify the
  3347. interaction of read-char with echo streams (as created by make-echo-stream). A
  3348. character is echoed from the input stream to the associated output stream the
  3349. first time it is seen. If a character is read again because of an intervening
  3350. unread-char operation, the character is not echoed again when read for the
  3351. second time or any subsequent time.
  3352. [change_end]
  3353.  
  3354. [Function]
  3355. unread-char character &optional input-stream
  3356.  
  3357. unread-char puts the character onto the front of input-stream. The character
  3358. must be the same character that was most recently read from the input-stream.
  3359. The input-stream ``backs up'' over this character; when a character is next
  3360. read from input-stream, it will be the specified character followed by the
  3361. previous contents of input-stream. unread-char returns nil.
  3362.  
  3363. One may apply unread-char only to the character most recently read from
  3364. input-stream. Moreover, one may not invoke unread-char twice consecutively
  3365. without an intervening read-char operation. The result is that one may back up
  3366. only by one character, and one may not insert any characters into the input
  3367. stream that were not already there.
  3368.  
  3369. [change_begin]
  3370. X3J13 voted in January 1989 (UNREAD-CHAR-AFTER-PEEK-CHAR)   to clarify that one
  3371. also may not invoke unread-char after invoking peek-char without an intervening
  3372. read-char operation. This is consistent with the notion that peek-char behaves
  3373. much like read-char followed by unread-char.
  3374. [change_end]
  3375.  
  3376. -------------------------------------------------------------------------------
  3377. Rationale: This is not intended to be a general mechanism, but rather an
  3378. efficient mechanism for allowing the Lisp reader and other parsers to perform
  3379. one-character lookahead in the input stream. This protocol admits a wide
  3380. variety of efficient implementations, such as simply decrementing a buffer
  3381. pointer. To have to specify the character in the call to unread-char is
  3382. admittedly redundant, since at any given time there is only one character that
  3383. may be legally specified. The redundancy is intentional, again to give the
  3384. implementation latitude.
  3385. -------------------------------------------------------------------------------
  3386.  
  3387. [change_begin]
  3388. X3J13 voted in January 1989 (PEEK-CHAR-READ-CHAR-ECHO)   to clarify the
  3389. interaction of unread-char with echo streams (as created by make-echo-stream).
  3390. When a character is ``unread'' from an echo stream, no attempt is made to
  3391. ``unecho'' the character. However, a character placed back into an echo stream
  3392. by unread-char will not be re-echoed when it is subsequently re-read by
  3393. read-char.
  3394. [change_end]
  3395.  
  3396. [Function]
  3397. peek-char &optional peek-type input-stream eof-error-p eof-value recursive-p
  3398.  
  3399. What peek-char does depends on the peek-type, which defaults to nil. With a
  3400. peek-type of nil, peek-char returns the next character to be read from
  3401. input-stream, without actually removing it from the input stream. The next time
  3402. input is done from input-stream, the character will still be there. It is as if
  3403. one had called read-char and then unread-char in succession.
  3404.  
  3405. If peek-type is t, then peek-char skips over whitespace characters (but not
  3406. comments) and then performs the peeking operation on the next character. This
  3407. is useful for finding the (possible) beginning of the next printed
  3408. representation of a Lisp object. The last character examined (the one that
  3409. starts an object) is not removed from the input stream.
  3410.  
  3411. If peek-type is a character object, then peek-char skips over input characters
  3412. until a character that is char= to that object is found; that character is left
  3413. in the input stream.
  3414.  
  3415. [change_begin]
  3416. X3J13 voted in January 1989 (PEEK-CHAR-READ-CHAR-ECHO)   to clarify the
  3417. interaction of peek-char with echo streams (as created by make-echo-stream).
  3418. When a character from an echo stream is only peeked at, it is not echoed at
  3419. that time. The character remains in the input stream and may be echoed when
  3420. read by read-char at a later time. Note, however, that if the peek-type is not
  3421. nil, then characters skipped over (and therefore consumed) by peek-char are
  3422. treated as if they had been read by read-char, and will be echoed if read-char
  3423. would have echoed them.
  3424. [change_end]
  3425.  
  3426. [Function]
  3427. listen &optional input-stream
  3428.  
  3429. The predicate listen is true if there is a character immediately available from
  3430. input-stream, and is false if not. This is particularly useful when the stream
  3431. obtains characters from an interactive device such as a keyboard. A call to
  3432. read-char would simply wait until a character was available, but listen can
  3433. sense whether or not input is available and allow the program to decide whether
  3434. or not to attempt input. On a non-interactive stream, the general rule is that
  3435. listen is true except when at end-of-file.
  3436.  
  3437. [Function]
  3438. read-char-no-hang &optional input-stream eof-error-p eof-value recursive-p
  3439.  
  3440. This function is exactly like read-char, except that if it would be necessary
  3441. to wait in order to get a character (as from a keyboard), nil is immediately
  3442. returned without waiting. This allows one to efficiently check for input
  3443. availability and get the input if it is available. This is different from the
  3444. listen operation in two ways. First, read-char-no-hang potentially reads a
  3445. character, whereas listen never inputs a character. Second, listen does not
  3446. distinguish between end-of-file and no input being available, whereas
  3447. read-char-no-hang does make that distinction, returning eof-value at
  3448. end-of-file (or signaling an error if no eof-error-p is true) but always
  3449. returning nil if no input is available.
  3450.  
  3451. [Function]
  3452. clear-input &optional input-stream
  3453.  
  3454. This clears any buffered input associated with input-stream. It is primarily
  3455. useful for clearing type-ahead from keyboards when some kind of asynchronous
  3456. error has occurred. If this operation doesn't make sense for the stream
  3457. involved, then clear-input does nothing. clear-input returns nil.
  3458.  
  3459. [Function]
  3460. read-from-string string &optional eof-error-p eof-value &key :start :end
  3461. :preserve-whitespace
  3462.  
  3463. The characters of string are given successively to the Lisp reader, and the
  3464. Lisp object built by the reader is returned. Macro characters and so on will
  3465. all take effect.
  3466.  
  3467. The arguments :start and :end delimit a substring of string beginning at the
  3468. character indexed by :start and up to but not including the character indexed
  3469. by :end. By default :start is 0 (the beginning of the string) and :end is
  3470. (length string). This is the same as for other string functions.
  3471.  
  3472. The flag :preserve-whitespace, if provided and not nil, indicates that the
  3473. operation should preserve whitespace as for read-preserving-whitespace. It
  3474. defaults to nil.
  3475.  
  3476. As with other reading functions, the arguments eof-error-p and eof-value
  3477. control the action if the end of the (sub)string is reached before the
  3478. operation is completed; reaching the end of the string is treated as any other
  3479. end-of-file event.
  3480.  
  3481. read-from-string returns two values: the first is the object read, and the
  3482. second is the index of the first character in the string not read. If the
  3483. entire string was read, the second result will be either the length of the
  3484. string or one greater than the length of the string. The parameter
  3485. :preserve-whitespace may affect this second value.
  3486.  
  3487. (read-from-string "(a b c)") => (a b c) and 7
  3488.  
  3489. [Function]
  3490. parse-integer string &key :start :end :radix :junk-allowed
  3491.  
  3492. This function examines the substring of string delimited by :start and :end
  3493. (which default to the beginning and end of the string). It skips over
  3494. whitespace characters and then attempts to parse an integer. The :radix
  3495. parameter defaults to 10 and must be an integer between 2 and 36.
  3496.  
  3497. If :junk-allowed is not nil, then the first value returned is the value of the
  3498. number parsed as an integer or nil if no syntactically correct integer was
  3499. seen.
  3500.  
  3501. If :junk-allowed is nil (the default), then the entire substring is scanned.
  3502. The returned value is the value of the number parsed as an integer. An error is
  3503. signaled if the substring does not consist entirely of the representation of an
  3504. integer, possibly surrounded on either side by whitespace characters.
  3505.  
  3506. In either case, the second value is the index into the string of the delimiter
  3507. that terminated the parse, or it is the index beyond the substring if the parse
  3508. terminated at the end of the substring (as will always be the case if
  3509. :junk-allowed is false).
  3510.  
  3511. Note that parse-integer does not recognize the syntactic radix-specifier
  3512. prefixes #O, #B, #X, and #nR, nor does it recognize a trailing decimal point.
  3513. It permits only an optional sign (+ or -) followed by a non-empty sequence of
  3514. digits in the specified radix.
  3515.  
  3516. -------------------------------------------------------------------------------
  3517.  
  3518. 22.2.2. Input from Binary Streams
  3519.  
  3520. Common Lisp currently specifies only a very simple facility for binary input:
  3521. the reading of a single byte as an integer.
  3522.  
  3523. [Function]
  3524. read-byte binary-input-stream &optional eof-error-p eof-value
  3525.  
  3526. read-byte reads one byte from the binary-input-stream and returns it in the
  3527. form of an integer.
  3528.  
  3529. -------------------------------------------------------------------------------
  3530.  
  3531. 22.3. Output Functions
  3532.  
  3533. The output functions are divided into two groups: those that operate on streams
  3534. of characters and those that operate on streams of binary data. The function
  3535. format operates on streams of characters but is described in a section separate
  3536. from the other character-output functions because of its great complexity.
  3537.  
  3538. -------------------------------------------------------------------------------
  3539.  
  3540.    *  Output to Character Streams
  3541.    *  Output to Binary Streams
  3542.    *  Formatted Output to Character Streams
  3543.  
  3544. -------------------------------------------------------------------------------
  3545.  
  3546. 22.3.1. Output to Character Streams
  3547.  
  3548. These functions all take an optional argument called output-stream, which is
  3549. where to send the output. If unsupplied or nil, output-stream defaults to the
  3550. value of the variable *standard-output*. If it is t, the value of the variable
  3551. *terminal-io* is used.
  3552.  
  3553. [old_change_begin]
  3554.  
  3555. [Function]
  3556. write object &key :stream :escape :radix :base :circle :pretty :level :length
  3557. :case :gensym :array
  3558.  
  3559. The printed representation of object is written to the output stream specified
  3560. by :stream, which defaults to the value of *standard-output*.
  3561.  
  3562. The other keyword arguments specify values used to control the generation of
  3563. the printed representation. Each defaults to the value of the corresponding
  3564. global variable: see *print-escape*, *print-radix*, *print-base*,
  3565. *print-circle*, *print-pretty*, *print-level*, *print-length*, *print-case*,
  3566. *print-array*, and *print-gensym*. (This is the means by which these variables
  3567. affect printing operations: supplying default values for the write function.)
  3568. Note that the printing of symbols is also affected by the value of the variable
  3569. *package*. write returns object.
  3570. [old_change_end]
  3571.  
  3572. [change_begin]
  3573. X3J13 voted in June 1989 (DATA-IO)   to add the keyword argument :readably to
  3574. the function write, and voted in June 1989 (PRETTY-PRINT-INTERFACE)   to add
  3575. the keyword arguments :right-margin, :miser-width, :lines, and
  3576. :pprint-dispatch. The revised description is as follows.
  3577.  
  3578. [Function]
  3579. write object &key :stream :escape :radix :base :circle :pretty :level :length
  3580. :case :gensym :array :readably :right-margin :miser-width :lines
  3581. :pprint-dispatch
  3582.  
  3583. The printed representation of object is written to the output stream specified
  3584. by :stream, which defaults to the value of *standard-output*.
  3585.  
  3586. The other keyword arguments specify values used to control the generation of
  3587. the printed representation. Each defaults to the value of the corresponding
  3588. global variable: see *print-escape*, *print-radix*, *print-base*,
  3589. *print-circle*, *print-pretty*, *print-level*, *print-length*, and
  3590. *print-case*, in addition to *print-array*, *print-gensym*, *print-readably*,
  3591. *print-right-margin*, *print-miser-width*, *print-lines*, and
  3592. *print-pprint-dispatch*. (This is the means by which these variables affect
  3593. printing operations: supplying default values for the write function.) Note
  3594. that the printing of symbols is also affected by the value of the variable
  3595. *package*. write returns object.
  3596. [change_end]
  3597.  
  3598. [Function]
  3599. prin1 object &optional output-stream
  3600. print object &optional output-stream
  3601. pprint object &optional output-stream
  3602. princ object &optional output-stream
  3603.  
  3604. prin1 outputs the printed representation of object to output-stream. Escape
  3605. characters are used as appropriate. Roughly speaking, the output from prin1 is
  3606. suitable for input to the function read. prin1 returns the object as its value.
  3607.  
  3608. (prin1 object output-stream)
  3609.    == (write object :stream output-stream :escape t)
  3610.  
  3611. print is just like prin1 except that the printed representation of object is
  3612. preceded by a newline (see terpri) and followed by a space. print returns
  3613. object.
  3614.  
  3615. pprint is just like print except that the trailing space is omitted and the
  3616. object is printed with the *print-pretty* flag non-nil to produce ``pretty''
  3617. output. pprint returns no values (that is, what the expression (values)
  3618. returns: zero values).
  3619.  
  3620. [change_begin]
  3621. X3J13 voted in January 1989 (PRETTY-PRINT-INTERFACE)   to adopt a facility for
  3622. user-controlled pretty printing (see chapter 27).
  3623. [change_end]
  3624.  
  3625. princ is just like prin1 except that the output has no escape characters. A
  3626. symbol is printed as simply the characters of its print name; a string is
  3627. printed without surrounding double quotes; and there may be differences for
  3628. other data types as well. The general rule is that output from princ is
  3629. intended to look good to people, while output from prin1 is intended to be
  3630. acceptable to the function read.
  3631.  
  3632. [change_begin]
  3633. X3J13 voted in June 1987 (PRINC-CHARACTER)   to clarify that princ prints a
  3634. character in exactly the same manner as write-char: the character is simply
  3635. sent to the output stream. This was implied by the specification in section
  3636. 22.1.6 in the first edition, but is worth pointing out explicitly here.
  3637. [change_end]
  3638.  
  3639. princ returns the object as its value.
  3640.  
  3641. (princ object output-stream)
  3642.    == (write object :stream output-stream :escape nil)
  3643.  
  3644. -------------------------------------------------------------------------------
  3645. Compatibility note: In MacLisp, the functions prin1, print, and princ return t,
  3646. not the argument object.
  3647. -------------------------------------------------------------------------------
  3648.  
  3649. [old_change_begin]
  3650.  
  3651. [Function]
  3652. write-to-string object &key :escape :radix :base :circle :pretty :level :length
  3653. :case :gensym :array
  3654. prin1-to-string object
  3655. princ-to-string object
  3656.  
  3657. The object is effectively printed as if by write, prin1, or princ,
  3658. respectively, and the characters that would be output are made into a string,
  3659. which is returned.
  3660. [old_change_end]
  3661.  
  3662. -------------------------------------------------------------------------------
  3663. Compatibility note: The Interlisp function mkstring corresponds to the Common
  3664. Lisp function princ-to-string.
  3665. -------------------------------------------------------------------------------
  3666.  
  3667. [change_begin]
  3668.  
  3669. [Function]
  3670. write-to-string object &key :escape :radix :base :circle :pretty :level :length
  3671. :case :gensym :array :readably :right-margin :miser-width :lines
  3672. :pprint-dispatch
  3673.  
  3674. X3J13 voted in June 1989 ((DATA-IO)   and (PRETTY-PRINT-INTERFACE)   ) to add
  3675. keyword arguments to write; presumably they should also be added to
  3676. write-to-string.
  3677. [change_end]
  3678.  
  3679. [Function]
  3680. write-char character &optional output-stream
  3681.  
  3682. write-char outputs the character to output-stream, and returns character.
  3683.  
  3684. [Function]
  3685. write-string string &optional output-stream &key :start :end
  3686. write-line string &optional output-stream &key :start :end
  3687.  
  3688. write-string writes the characters of the specified substring of string to the
  3689. output-stream. The :start and :end parameters delimit a substring of string in
  3690. the usual manner (see chapter 14). write-line does the same thing but then
  3691. outputs a newline afterwards. (See read-line.) In either case, the string is
  3692. returned (not the substring delimited by :start and :end). In some
  3693. implementations these may be much more efficient than an explicit loop using
  3694. write-char.
  3695.  
  3696. [Function]
  3697. terpri &optional output-stream
  3698. fresh-line &optional output-stream
  3699.  
  3700. The function terpri outputs a newline to output-stream. It is identical in
  3701. effect to (write-char #\Newline output-stream); however, terpri always returns
  3702. nil.
  3703.  
  3704. fresh-line is similar to terpri but outputs a newline only if the stream is not
  3705. already at the start of a line. (If for some reason this cannot be determined,
  3706. then a newline is output anyway.) This guarantees that the stream will be on a
  3707. ``fresh line'' while consuming as little vertical distance as possible.
  3708. fresh-line is a predicate that is true if it output a newline, and otherwise
  3709. false.
  3710.  
  3711. [Function]
  3712. finish-output &optional output-stream
  3713. force-output &optional output-stream
  3714. clear-output &optional output-stream
  3715.  
  3716. Some streams may be implemented in an asynchronous or buffered manner. The
  3717. function finish-output attempts to ensure that all output sent to output-stream
  3718. has reached its destination, and only then returns nil. force-output initiates
  3719. the emptying of any internal buffers but returns nil without waiting for
  3720. completion or acknowledgment.
  3721.  
  3722. The function clear-output, on the other hand, attempts to abort any outstanding
  3723. output operation in progress in order to allow as little output as possible to
  3724. continue to the destination. This is useful, for example, to abort a lengthy
  3725. output to the terminal when an asynchronous error occurs. clear-output returns
  3726. nil.
  3727.  
  3728. The precise actions of all three of these operations are
  3729. implementation-dependent.
  3730.  
  3731. [change_begin]
  3732.  
  3733. [Macro]
  3734.  
  3735. print-unreadable-object (object stream
  3736.                          [[ :type type | :identity id ]])
  3737.                          {declaration}* {form}*
  3738.  
  3739. X3J13 voted in June 1989 (DATA-IO)   to add print-unreadable-object, which will
  3740. output a printed representation of object on stream, beginning with #< and
  3741. ending with >. Everything output to the stream during execution of the body
  3742. forms is enclosed in the angle brackets. If type is true, the body output is
  3743. preceded by a brief description of the object's type and a space character. If
  3744. id is true, the body output is followed by a space character and a
  3745. representation of the object's identity, typically a storage address.
  3746.  
  3747. If *print-readably* is true, print-unreadable-object signals an error of type
  3748. print-not-readable without printing anything.
  3749.  
  3750. The object, stream, type, and id arguments are all evaluated normally. The type
  3751. and id default to false. It is valid to provide no body forms. If type and id
  3752. are both true and there are no body forms, only one space character separates
  3753. the printed type and the printed identity.
  3754.  
  3755. The value returned by print-unreadable-object is nil.
  3756.  
  3757. (defmethod print-object ((obj airplane) stream)
  3758.   (print-unreadable-object (obj stream :type t :identity t)
  3759.     (princ (tail-number obj) stream)))
  3760. (print my-airplane)  prints
  3761. #<Airplane NW0773 777500123135>     ;In implementation A
  3762.                      or perhaps
  3763. #<FAA:AIRPLANE NW0773 17>           ;In implementation B
  3764.  
  3765. The big advantage of print-unreadable-object is that it allows a user to write
  3766. print-object methods that adhere to implementation-specific style without
  3767. requiring the user to write implementation-dependent code.
  3768.  
  3769. The X3J13 vote left it unclear whether print-unreadable-object permits
  3770. declarations to appear before the body of the macro call. I believe that was
  3771. the intent, and this is reflected in the syntax shown above; but this is only
  3772. my interpretation.
  3773. [change_end]
  3774.  
  3775. -------------------------------------------------------------------------------
  3776.  
  3777. 22.3.2. Output to Binary Streams
  3778.  
  3779. Common Lisp currently specifies only a very simple facility for binary output:
  3780. the writing of a single byte as an integer.
  3781.  
  3782. [Function]
  3783. write-byte integer binary-output-stream
  3784.  
  3785. write-byte writes one byte, the value of integer. It is an error if integer is
  3786. not of the type specified as the :element-type argument to open when the stream
  3787. was created. The value integer is returned.
  3788.  
  3789. -------------------------------------------------------------------------------
  3790.  
  3791. 22.3.3. Formatted Output to Character Streams
  3792.  
  3793. The function format is very useful for producing nicely formatted text,
  3794. producing good-looking messages, and so on. format can generate a string or
  3795. output to a stream.
  3796.  
  3797. Formatted output is performed not only by the format function itself but by
  3798. certain other functions that accept a control string ``the way format does.''
  3799. For example, error-signaling functions such as cerror accept format control
  3800. strings.
  3801.  
  3802. [Function]
  3803. format destination control-string &rest arguments
  3804.  
  3805. format is used to produce formatted output. format outputs the characters of
  3806. control-string, except that a tilde (~) introduces a directive. The character
  3807. after the tilde, possibly preceded by prefix parameters and modifiers,
  3808. specifies what kind of formatting is desired. Most directives use one or more
  3809. elements of arguments to create their output; the typical directive puts the
  3810. next element of arguments into the output, formatted in some special way. It is
  3811. an error if no argument remains for a directive requiring an argument, but it
  3812. is not an error if one or more arguments remain unprocessed by a directive.
  3813.  
  3814. The output is sent to destination. If destination is nil, a string is created
  3815. that contains the output; this string is returned as the value of the call to
  3816. format.
  3817.  
  3818. [change_begin]
  3819. X3J13 voted in January 1989 (STREAM-ACCESS)   to specify that when the first
  3820. argument to format is nil, format creates a stream of type string-stream in
  3821. much the same manner as with-output-to-string. (This stream may be visible to
  3822. the user if, for example, the ~S directive is used to print a defstruct
  3823. structure that has a user-supplied print function.)
  3824. [change_end]
  3825.  
  3826. In all other cases format returns nil, performing output to destination as a
  3827. side effect. If destination is a stream, the output is sent to it. If
  3828. destination is t, the output is sent to the stream that is the value of the
  3829. variable *standard-output*. If destination is a string with a fill pointer,
  3830. then in effect the output characters are added to the end of the string (as if
  3831. by use of vector-push-extend).
  3832.  
  3833. The format function includes some extremely complicated and specialized
  3834. features. It is not necessary to understand all or even most of its features to
  3835. use format effectively. The beginner should skip over anything in the following
  3836. documentation that is not immediately useful or clear. The more sophisticated
  3837. features (such as conditionals and iteration) are there for the convenience of
  3838. programs with especially complicated formatting requirements.
  3839.  
  3840. A format directive consists of a tilde (~), optional prefix parameters
  3841. separated by commas, optional colon (:) and at-sign (@) modifiers, and a single
  3842. character indicating what kind of directive this is. The alphabetic case of the
  3843. directive character is ignored. The prefix parameters are generally integers,
  3844. notated as optionally signed decimal numbers.
  3845.  
  3846. [change_begin]
  3847. X3J13 voted in June 1987 (FORMAT-ATSIGN-COLON)   to specify that if both colon
  3848. and at-sign modifiers are present, they may appear in either order; thus ~:@R
  3849. and ~@:R mean the same thing. However, it is traditional to put the colon
  3850. first, and all the examples in this book put colons before at-signs.
  3851. [change_end]
  3852.  
  3853. Examples of control strings:
  3854.  
  3855. "~S"           ;An ~S directive with no parameters or modifiers
  3856. "~3,-4:@s"     ;An ~S directive with two parameters, 3 and -4,
  3857.                ; and both the colon and at-sign flags
  3858. "~,+4S"        ;First prefix parameter is omitted and takes
  3859.                ; on its default value; the second parameter is 4
  3860.  
  3861. Sometimes a prefix parameter is used to specify a character, for instance the
  3862. padding character in a right- or left-justifying operation. In this case a
  3863. single quote (') followed by the desired character may be used as a prefix
  3864. parameter, to mean the character object that is the character following the
  3865. single quote. For example, you can use ~5,'0d to print an integer in decimal
  3866. radix in five columns with leading zeros, or ~5,'*d to get leading asterisks.
  3867.  
  3868. In place of a prefix parameter to a directive, you can put the letter V (or v),
  3869. which takes an argument from arguments for use as a parameter to the directive.
  3870. Normally this should be an integer or character object, as appropriate. This
  3871. feature allows variable-width fields and the like. If the argument used by a V
  3872. parameter is nil, the effect is as if the parameter had been omitted. You may
  3873. also use the character # in place of a parameter; it represents the number of
  3874. arguments remaining to be processed.
  3875.  
  3876. It is an error to give a format directive more parameters than it is described
  3877. here as accepting. It is also an error to give colon or at-sign modifiers to a
  3878. directive in a combination not specifically described here as being meaningful.
  3879.  
  3880. [change_begin]
  3881. X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to clarify the interaction
  3882. between format and the various printer control variables (those named
  3883. *print-xxx*). This is important because many format operations are defined,
  3884. directly or indirectly, in terms of prin1 or princ, which are affected by the
  3885. printer control variables. The general rule is that format does not bind any of
  3886. the standard printer control variables except as specified in the individual
  3887. descriptions of directives. An implementation may not bind any standard printer
  3888. control variable not specified in the description of a format directive, nor
  3889. may an implementation fail to bind any standard printer control variables that
  3890. is specified to be bound by such a description. (See these descriptions for
  3891. specific changes voted by X3J13.)
  3892.  
  3893. One consequence of this change is that the user is guaranteed to be able to use
  3894. the format ~A and ~S directives to do pretty printing, under control of the
  3895. *print-pretty* variable. Implementations have differed on this point in their
  3896. interpretations of the first edition. The new ~W directive may be more
  3897. appropriate than either ~A and ~S for some purposes, whether for pretty
  3898. printing or ordinary printing. See section 27.4 for a discussion of ~W and
  3899. other new format directives related to pretty printing.
  3900. [change_end]
  3901.  
  3902. Here are some relatively simple examples to give you the general flavor of how
  3903. format is used.
  3904.  
  3905. (format nil "foo") => "foo"
  3906.  
  3907. (setq x 5)
  3908.  
  3909. (format nil "The answer is ~D." x) => "The answer is 5."
  3910.  
  3911. (format nil "The answer is ~3D." x) => "The answer is   5."
  3912.  
  3913. (format nil "The answer is ~3,'0D." x) => "The answer is 005."
  3914.  
  3915. (format nil "The answer is ~:D." (expt 47 x))
  3916.                                 => "The answer is 229,345,007."
  3917.  
  3918. (setq y "elephant")
  3919.  
  3920. (format nil "Look at the ~A!" y) => "Look at the elephant!"
  3921.  
  3922. (format nil "Type ~:C to ~A."
  3923.         (set-char-bit #\D :control t)
  3924.         "delete all your files")
  3925.    => "Type Control-D to delete all your files."
  3926.  
  3927. (setq n 3)
  3928.  
  3929. (format nil "~D item~:P found." n) => "3 items found."
  3930.  
  3931. (format nil "~R dog~:[s are~; is~] here." n (= n 1))
  3932.       => "three dogs are here."
  3933.  
  3934. (format nil "~R dog~:*~[s are~; is~:;s are~] here." n)
  3935.       => "three dogs are here."
  3936.  
  3937. (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n)
  3938.       => "Here are three puppies."
  3939.  
  3940. In the descriptions of the directives that follow, the term arg in general
  3941. refers to the next item of the set of arguments to be processed. The word or
  3942. phrase at the beginning of each description is a mnemonic (not necessarily an
  3943. accurate one) for the directive.
  3944.  
  3945. ~A   Ascii. An arg, any Lisp object, is printed without escape characters (as
  3946.      by princ). In particular, if arg is a string, its characters will be
  3947.      output verbatim. If arg is nil, it will be printed as nil; the colon
  3948.      modifier (~:A) will cause an arg of nil to be printed as (), but if arg is
  3949.      a composite structure, such as a list or vector, any contained occurrences
  3950.      of nil will still be printed as nil.
  3951.  
  3952.      ~mincolA inserts spaces on the right, if necessary, to make the width at
  3953.      least mincol columns. The @ modifier causes the spaces to be inserted on
  3954.      the left rather than the right.
  3955.  
  3956.      ~mincol,colinc,minpad,padcharA is the full form of ~A, which allows
  3957.      elaborate control of the padding. The string is padded on the right (or on
  3958.      the left if the @ modifier is used) with at least minpad copies of
  3959.      padchar; padding characters are then inserted colinc characters at a time
  3960.      until the total width is at least mincol. The defaults are 0 for mincol
  3961.      and minpad, 1 for colinc, and the space character for padchar.
  3962.  
  3963.      [change_begin]
  3964.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  3965.      binds *print-escape* to nil during the processing of the ~A directive.
  3966.      [change_end]
  3967.  
  3968. ~S   S-expression. This is just like ~A, but arg is printed with escape
  3969.      characters (as by prin1 rather than princ). The output is therefore
  3970.      suitable for input to read. ~S accepts all the arguments and modifiers
  3971.      that ~A does.
  3972.  
  3973.      [change_begin]
  3974.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  3975.      binds *print-escape* to t during the processing of the ~S directive.
  3976.      [change_end]
  3977.  
  3978. ~D   Decimal. An arg, which should be an integer, is printed in decimal radix.
  3979.      ~D will never put a decimal point after the number.
  3980.  
  3981.      ~mincolD uses a column width of mincol; spaces are inserted on the left if
  3982.      the number requires fewer than mincol columns for its digits and sign. If
  3983.      the number doesn't fit in mincol columns, additional columns are used as
  3984.      needed.
  3985.  
  3986.      ~mincol,padcharD uses padchar as the pad character instead of space.
  3987.  
  3988.      If arg is not an integer, it is printed in ~A format and decimal base.
  3989.  
  3990.      [change_begin]
  3991.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  3992.      binds *print-escape* to nil, *print-radix* to nil, and *print-base* to 10
  3993.      during processing of ~D.
  3994.      [change_end]
  3995.  
  3996.      The @ modifier causes the number's sign to be printed always; the default
  3997.      is to print it only if the number is negative. The : modifier causes
  3998.      commas to be printed between groups of three digits; the third prefix
  3999.      parameter may be used to change the character used as the comma. Thus the
  4000.      most general form of ~D is ~mincol,padchar,commacharD.
  4001.  
  4002.      [change_begin]
  4003.      X3J13 voted in March 1988 (FORMAT-COMMA-INTERVAL)   to add a fourth
  4004.      parameter, the commainterval. This must be an integer; if it is not
  4005.      provided, it defaults to 3. This parameter controls the number of digits
  4006.      in each group separated by the commachar.
  4007.  
  4008.      By extension, each of the ~B, ~O, and ~X directives accepts a
  4009.      commainterval as a fourth parameter, and the ~R directive accepts a
  4010.      commainterval as its fifth parameter. Examples:
  4011.  
  4012.      (format nil "~,,' ,4B" #xFACE) => "1111 1010 1100 1110"
  4013.      (format nil "~,,' ,4B" #x1CE) => "1 1100 1110"
  4014.      (format nil "~19,,' ,4B" #xFACE) => "1111 1010 1100 1110"
  4015.      (format nil "~19,,' ,4B" #x1CE) => "0000 0001 1100 1110"
  4016.  
  4017.      This is one of those little improvements that probably don't matter much
  4018.      but aren't hard to implement either. It was pretty silly having the number
  4019.      3 wired into the definition of comma separation when it is just as easy to
  4020.      make it a parameter.
  4021.      [change_end]
  4022.  
  4023. ~B   Binary. This is just like ~D but prints in binary radix (radix 2) instead
  4024.      of decimal. The full form is therefore ~mincol,padchar,commacharB.
  4025.  
  4026.      [change_begin]
  4027.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4028.      binds *print-escape* to nil, *print-radix* to nil, and *print-base* to 2
  4029.      during processing of ~B.
  4030.      [change_end]
  4031.  
  4032. ~O   Octal. This is just like ~D but prints in octal radix (radix 8) instead of
  4033.      decimal. The full form is therefore ~mincol,padchar,commacharO.
  4034.  
  4035.      [change_begin]
  4036.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4037.      binds *print-escape* to nil, *print-radix* to nil, and *print-base* to 8
  4038.      during processing of ~O.
  4039.      [change_end]
  4040.  
  4041. ~X   Hexadecimal. This is just like ~D but prints in hexadecimal radix (radix
  4042.      16) instead of decimal. The full form is therefore
  4043.      ~mincol,padchar,commacharX.
  4044.  
  4045.      [change_begin]
  4046.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4047.      binds *print-escape* to nil, *print-radix* to nil, and *print-base* to 16
  4048.      during processing of ~X.
  4049.      [change_end]
  4050.  
  4051. -------------------------------------------------------------------------------
  4052. Compatibility note: In MacLisp and Lisp Machine Lisp the ~X directive outputs a
  4053. space, and ~nX outputs n spaces, in a manner analogous to Fortran X format. In
  4054. Common Lisp the directive ~@T is used for that purpose.
  4055. -------------------------------------------------------------------------------
  4056.  
  4057. ~R   Radix. ~nR prints arg in radix n. The modifier flags and any remaining
  4058.      parameters are used as for the ~D directive. Indeed, ~D is the same as
  4059.      ~10R. The full form here is therefore ~radix,mincol,padchar,commacharR.
  4060.  
  4061.      [change_begin]
  4062.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4063.      binds *print-escape* to nil, *print-radix* to nil, and *print-base* to the
  4064.      value of the first parameter during the processing of the ~R directive
  4065.      with a parameter.
  4066.      [change_end]
  4067.  
  4068.      If no parameters are given to ~R, then an entirely different
  4069.      interpretation is given.
  4070.  
  4071.      [change_begin]
  4072.      Notice of correction. In the first edition, this sentence referred to
  4073.      ``arguments'' given to ~R. The correct term is ``parameters.''
  4074.      [change_end]
  4075.  
  4076.      The argument should be an integer; suppose it is 4. Then ~R prints arg as
  4077.      a cardinal English number: four; ~:R prints arg as an ordinal English
  4078.      number: fourth; ~@R prints arg as a Roman numeral: IV; and ~:@R prints arg
  4079.      as an old Roman numeral: IIII.
  4080.  
  4081.      [change_begin]
  4082.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4083.      binds *print-base* to 10 during the processing of the ~R directive with no
  4084.      parameter.
  4085.  
  4086.      The first edition did not specify how ~R and its variants should handle
  4087.      arguments that are very large or not positive. Actual practice varies, and
  4088.      X3J13 has not yet addressed the topic. Here is a sampling of current
  4089.      practice.
  4090.  
  4091.      For ~@R and ~:@R, nearly all implementations produce Roman numerals only
  4092.      for integers in the range 1 to 3999, inclusive. Some implementations will
  4093.      produce old-style Roman numerals for integers in the range 1 to 4999,
  4094.      inclusive. All other integers are printed in decimal notation, as if ~D
  4095.      had been used.
  4096.  
  4097.      For zero, most implementations print zero for ~R and zeroth for ~:R.
  4098.  
  4099.      For ~R with a negative argument, most implementations simply print the
  4100.      word minus followed by its absolute value as a cardinal in English.
  4101.  
  4102.      For ~:R with a negative argument, some implementations also print the word
  4103.      minus followed by its absolute value as an ordinal in English; other
  4104.      implementations print the absolute value followed by the word previous.
  4105.      Thus the argument -4 might produce minus fourth or fourth previous. Each
  4106.      has its charm, but one is not always a suitable substitute for the other;
  4107.      users should be careful.
  4108.  
  4109.      There is standard English nomenclature for fairly large integers (up to
  4110.        , at least), based on appending the suffix -illion to Latin names of
  4111.      integers. Thus we have the names trillion, quadrillion, sextillion,
  4112.      septillion, and so on. For extremely large integers, one may express
  4113.      powers of ten in English. One implementation gives
  4114.      1606938044258990275541962092341162602522202993782792835301376 (which is
  4115.        , the result of (ash 1 200)) in this manner:
  4116.  
  4117.      one times ten to the sixtieth power six hundred six times ten to the
  4118.      fifty-seventh power nine hundred thirty-eight septdecillion forty-four
  4119.      sexdecillion two hundred fifty-eight quindecillion nine hundred ninety
  4120.      quattuordecillion two hundred seventy-five tredecillion five hundred
  4121.      forty-one duodecillion nine hundred sixty-two undecillion ninety-two
  4122.      decillion three hundred forty-one nonillion one hundred sixty-two
  4123.      octillion six hundred two septillion five hundred twenty-two sextillion
  4124.      two hundred two quintillion nine hundred ninety-three quadrillion seven
  4125.      hundred eighty-two trillion seven hundred ninety-two billion eight
  4126.      hundred thirty-five million three hundred one thousand three hundred
  4127.      seventy-six
  4128.  
  4129.      Another implementation prints it this way (note the use of plus):
  4130.  
  4131.      one times ten to the sixtieth power plus six hundred six times ten to
  4132.      the fifty-seventh power plus ... plus two hundred seventy-five times
  4133.      ten to the forty-second power plus five hundred forty-one duodecillion
  4134.      nine hundred sixty-two undecillion ...  three hundred seventy-six
  4135.  
  4136.      (I have elided some of the text here to save space.)
  4137.  
  4138.      Unfortunately, the meaning of this nomenclature differs between American
  4139.      English (in which k-illion means   , so one trillion is   ) and British
  4140.      English (in which k-illion means   , so one trillion is   ). To avoid both
  4141.      confusion and prolixity, I recommend using decimal notation for all
  4142.      numbers above 999,999,999; this is similar to the escape hatch used for
  4143.      Roman numerals.
  4144.      [change_end]
  4145.  
  4146. ~P   Plural. If arg is not eql to the integer 1, a lowercase s is printed; if
  4147.      arg is eql to 1, nothing is printed. (Notice that if arg is a
  4148.      floating-point 1.0, the s is printed.) ~:P does the same thing, after
  4149.      doing a ~:* to back up one argument; that is, it prints a lowercase s if
  4150.      the last argument was not 1. This is useful after printing a number using
  4151.      ~D. ~@P prints y if the argument is 1, or ies if it is not. ~:@P does the
  4152.      same thing, but backs up first.
  4153.  
  4154.      (format nil "~D tr~:@P/~D win~:P" 7 1) => "7 tries/1 win"
  4155.      (format nil "~D tr~:@P/~D win~:P" 1 0) => "1 try/0 wins"
  4156.      (format nil "~D tr~:@P/~D win~:P" 1 3) => "1 try/3 wins"
  4157.  
  4158. ~C   Character. The next arg should be a character; it is printed according to
  4159.      the modifier flags.
  4160.  
  4161.      [old_change_begin]
  4162.      ~C prints the character in an implementation-dependent abbreviated format.
  4163.      This format should be culturally compatible with the host environment.
  4164.      [old_change_end]
  4165.  
  4166.      [change_begin]
  4167.      X3J13 voted in June 1987 (FORMAT-OP-C)   to specify that ~C performs
  4168.      exactly the same action as write-char if the character to be printed has
  4169.      zero for its bits attributes. X3J13 voted in March 1989
  4170.      (CHARACTER-PROPOSAL)   to eliminate the bits and font attributes,
  4171.      replacing them with the notion of implementation-defined attributes. The
  4172.      net effect is that characters whose implementation-defined attributes all
  4173.      have the ``standard'' values should be printed by ~C in the same way that
  4174.      write-char would print them.
  4175.      [change_end]
  4176.  
  4177.      ~:C spells out the names of the control bits and represents non-printing
  4178.      characters by their names: Control-Meta-F, Control-Return, Space. This is
  4179.      a ``pretty'' format for printing characters.
  4180.  
  4181.      ~:@C prints what ~:C would, and then if the character requires unusual
  4182.      shift keys on the keyboard to type it, this fact is mentioned: Control-
  4183.      (Top-F). This is the format for telling the user about a key he or she is
  4184.      expected to type, in prompts, for instance. The precise output may depend
  4185.      not only on the implementation but on the particular I/O devices in use.
  4186.  
  4187.      ~@C prints the character so that the Lisp reader can read it, using #\
  4188.      syntax.
  4189.  
  4190.      [change_begin]
  4191.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4192.      binds *print-escape* to t during the processing of the ~@C directive.
  4193.      Other variants of the ~C directive do not bind any printer control
  4194.      variables.
  4195.      [change_end]
  4196.  
  4197. -------------------------------------------------------------------------------
  4198. Rationale: In some implementations the ~S directive would do what ~C does, but
  4199. ~C is compatible with Lisp dialects such as MacLisp that do not have a
  4200. character data type.
  4201. -------------------------------------------------------------------------------
  4202.  
  4203. ~F   Fixed-format floating-point. The next arg is printed as a floating-point
  4204.      number.
  4205.  
  4206.      The full form is ~w,d,k,overflowchar,padcharF. The parameter w is the
  4207.      width of the field to be printed; d is the number of digits to print after
  4208.      the decimal point; k is a scale factor that defaults to zero.
  4209.  
  4210.      Exactly w characters will be output. First, leading copies of the
  4211.      character padchar (which defaults to a space) are printed, if necessary,
  4212.      to pad the field on the left. If the arg is negative, then a minus sign is
  4213.      printed; if the arg is not negative, then a plus sign is printed if and
  4214.      only if the @ modifier was specified. Then a sequence of digits,
  4215.      containing a single embedded decimal point, is printed; this represents
  4216.      the magnitude of the value of arg times   , rounded to d fractional
  4217.      digits. (When rounding up and rounding down would produce printed values
  4218.      equidistant from the scaled value of arg, then the implementation is free
  4219.      to use either one. For example, printing the argument 6.375 using the
  4220.      format ~4,2F may correctly produce either 6.37 or 6.38.) Leading zeros are
  4221.      not permitted, except that a single zero digit is output before the
  4222.      decimal point if the printed value is less than 1, and this single zero
  4223.      digit is not output after all if w=d+1.
  4224.  
  4225.      If it is impossible to print the value in the required format in a field
  4226.      of width w, then one of two actions is taken. If the parameter
  4227.      overflowchar is specified, then w copies of that parameter are printed
  4228.      instead of the scaled value of arg. If the overflowchar parameter is
  4229.      omitted, then the scaled value is printed using more than w characters, as
  4230.      many more as may be needed.
  4231.  
  4232.      If the w parameter is omitted, then the field is of variable width. In
  4233.      effect, a value is chosen for w in such a way that no leading pad
  4234.      characters need to be printed and exactly d characters will follow the
  4235.      decimal point. For example, the directive ~,2F will print exactly two
  4236.      digits after the decimal point and as many as necessary before the decimal
  4237.      point.
  4238.  
  4239.      If the parameter d is omitted, then there is no constraint on the number
  4240.      of digits to appear after the decimal point. A value is chosen for d in
  4241.      such a way that as many digits as possible may be printed subject to the
  4242.      width constraint imposed by the parameter w and the constraint that no
  4243.      trailing zero digits may appear in the fraction, except that if the
  4244.      fraction to be printed is zero, then a single zero digit should appear
  4245.      after the decimal point if permitted by the width constraint.
  4246.  
  4247.      If both w and d are omitted, then the effect is to print the value using
  4248.      ordinary free-format output; prin1 uses this format for any number whose
  4249.      magnitude is either zero or between    (inclusive) and    (exclusive).
  4250.  
  4251.      If w is omitted, then if the magnitude of arg is so large (or, if d is
  4252.      also omitted, so small) that more than 100 digits would have to be
  4253.      printed, then an implementation is free, at its discretion, to print the
  4254.      number using exponential notation instead, as if by the directive ~E (with
  4255.      all parameters to ~E defaulted, not taking their values from the ~F
  4256.      directive).
  4257.  
  4258.      If arg is a rational number, then it is coerced to be a single-float and
  4259.      then printed. (Alternatively, an implementation is permitted to process a
  4260.      rational number by any other method that has essentially the same behavior
  4261.      but avoids such hazards as loss of precision or overflow because of the
  4262.      coercion. However, note that if w and d are unspecified and the number has
  4263.      no exact decimal representation, for example 1/3, some precision cutoff
  4264.      must be chosen by the implementation: only a finite number of digits may
  4265.      be printed.)
  4266.  
  4267.      If arg is a complex number or some non-numeric object, then it is printed
  4268.      using the format directive ~wD, thereby printing it in decimal radix and a
  4269.      minimum field width of w. (If it is desired to print each of the real part
  4270.      and imaginary part of a complex number using a ~F directive, then this
  4271.      must be done explicitly with two ~F directives and code to extract the two
  4272.      parts of the complex number.)
  4273.  
  4274.      [change_begin]
  4275.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4276.      binds *print-escape* to nil during the processing of the ~F directive.
  4277.      [change_end]
  4278.  
  4279.      (defun foo (x)
  4280.        (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F"
  4281.                x x x x x x))
  4282.      (foo 3.14159)  => "  3.14| 31.42|  3.14|3.1416|3.14|3.14159"
  4283.      (foo -3.14159) => " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159"
  4284.      (foo 100.0)    => "100.00|******|100.00| 100.0|100.00|100.0"
  4285.      (foo 1234.0)   => "1234.00|******|??????|1234.0|1234.00|1234.0"
  4286.      (foo 0.006)    => "  0.01|  0.06|  0.01| 0.006|0.01|0.006"
  4287.  
  4288. -------------------------------------------------------------------------------
  4289. Compatibility note: The ~F directive is similar to the Fw.d edit descriptor in
  4290. Fortran.
  4291.  
  4292. The presence or absence of the @ modifier corresponds to the effect of the
  4293. Fortran SS or SP edit descriptor; nothing in Common Lisp corresponds to the
  4294. Fortran S edit descriptor.
  4295.  
  4296. The scale factor specified by the parameter k corresponds to the scale factor k
  4297. specified by the Fortran kP edit descriptor.
  4298.  
  4299. In Fortran, the leading zero that precedes the decimal point when the printed
  4300. value is less than 1 is optional; in Common Lisp, the implementation is
  4301. required to print that zero digit.
  4302.  
  4303. In Common Lisp, the w and d parameters are optional; in Fortran, they are
  4304. required.
  4305.  
  4306. In Common Lisp, the pad character and overflow character are user-specifiable;
  4307. in Fortran, they are always space and asterisk, respectively.
  4308.  
  4309. A Fortran implementation is prohibited from printing a representation of
  4310. negative zero; Common Lisp permits the printing of such a representation when
  4311. appropriate.
  4312.  
  4313. In MacLisp and Lisp Machine Lisp, the ~F format directive takes a single
  4314. parameter: the number of digits to use in the printed representation. This
  4315. incompatibility between Common Lisp and MacLisp was introduced for the sake of
  4316. cultural compatibility with Fortran.
  4317. -------------------------------------------------------------------------------
  4318.  
  4319. ~E   Exponential floating-point. The next arg is printed in exponential
  4320.      notation.
  4321.  
  4322.      The full form is ~w,d,e,k,overflowchar,padchar,exponentcharE. The
  4323.      parameter w is the width of the field to be printed; d is the number of
  4324.      digits to print after the decimal point; e is the number of digits to use
  4325.      when printing the exponent; k is a scale factor that defaults to 1 (not
  4326.      zero).
  4327.  
  4328.      Exactly w characters will be output. First, leading copies of the
  4329.      character padchar (which defaults to a space) are printed, if necessary,
  4330.      to pad the field on the left. If the arg is negative, then a minus sign is
  4331.      printed; if the arg is not negative, then a plus sign is printed if and
  4332.      only if the @ modifier was specified. Then a sequence of digits,
  4333.      containing a single embedded decimal point, is printed. The form of this
  4334.      sequence of digits depends on the scale factor k. If k is zero, then d
  4335.      digits are printed after the decimal point, and a single zero digit
  4336.      appears before the decimal point if the total field width will permit it.
  4337.      If k is positive, then it must be strictly less than d+2; k significant
  4338.      digits are printed before the decimal point, and d-k+1 digits are printed
  4339.      after the decimal point. If k is negative, then it must be strictly
  4340.      greater than -d; a single zero digit appears before the decimal point if
  4341.      the total field width will permit it, and after the decimal point are
  4342.      printed first -k zeros and then d+k significant digits. The printed
  4343.      fraction must be properly rounded. (When rounding up and rounding down
  4344.      would produce printed values equidistant from the scaled value of arg,
  4345.      then the implementation is free to use either one. For example, printing
  4346.      637.5 using the format ~8,2E may correctly produce either 6.37E+02 or
  4347.      6.38E+02.)
  4348.  
  4349.      Following the digit sequence, the exponent is printed. First the character
  4350.      parameter exponentchar is printed; if this parameter is omitted, then the
  4351.      exponent marker that prin1 would use is printed, as determined from the
  4352.      type of the floating-point number and the current value of
  4353.      *read-default-float-format*. Next, either a plus sign or a minus sign is
  4354.      printed, followed by e digits representing the power of 10 by which the
  4355.      printed fraction must be multiplied to properly represent the rounded
  4356.      value of arg.
  4357.  
  4358.      If it is impossible to print the value in the required format in a field
  4359.      of width w, possibly because k is too large or too small or because the
  4360.      exponent cannot be printed in e character positions, then one of two
  4361.      actions is taken. If the parameter overflowchar is specified, then w
  4362.      copies of that parameter are printed instead of the scaled value of arg.
  4363.      If the overflowchar parameter is omitted, then the scaled value is printed
  4364.      using more than w characters, as many more as may be needed; if the
  4365.      problem is that d is too small for the specified k or that e is too small,
  4366.      then a larger value is used for d or e as may be needed.
  4367.  
  4368.      If the w parameter is omitted, then the field is of variable width. In
  4369.      effect a value is chosen for w in such a way that no leading pad
  4370.      characters need to be printed.
  4371.  
  4372.      If the parameter d is omitted, then there is no constraint on the number
  4373.      of digits to appear. A value is chosen for d in such a way that as many
  4374.      digits as possible may be printed subject to the width constraint imposed
  4375.      by the parameter w, the constraint of the scale factor k, and the
  4376.      constraint that no trailing zero digits may appear in the fraction, except
  4377.      that if the fraction to be printed is zero, then a single zero digit
  4378.      should appear after the decimal point if the width constraint allows it.
  4379.  
  4380.      If the parameter e is omitted, then the exponent is printed using the
  4381.      smallest number of digits necessary to represent its value.
  4382.  
  4383.      If all of w, d, and e are omitted, then the effect is to print the value
  4384.      using ordinary free-format exponential-notation output; prin1 uses this
  4385.      format for any non-zero number whose magnitude is less than    or greater
  4386.      than or equal to   .
  4387.  
  4388.      [change_begin]
  4389.      X3J13 voted in January 1989 (FORMAT-E-EXPONENT-SIGN)   to amend the
  4390.      previous paragraph as follows:
  4391.  
  4392.      If all of w, d, and e are omitted, then the effect is to print the value
  4393.      using ordinary free-format exponential-notation output; prin1 uses a
  4394.      similar format for any non-zero number whose magnitude is less than    or
  4395.      greater than or equal to   . The only difference is that the ~E directive
  4396.      always prints a plus or minus sign before the exponent, while prin1 omits
  4397.      the plus sign if the exponent is non-negative.
  4398.  
  4399.      (The amendment reconciles this paragraph with the specification several
  4400.      paragraphs above that ~E always prints a plus or minus sign before the
  4401.      exponent.)
  4402.      [change_end]
  4403.  
  4404.      If arg is a rational number, then it is coerced to be a single-float and
  4405.      then printed. (Alternatively, an implementation is permitted to process a
  4406.      rational number by any other method that has essentially the same behavior
  4407.      but avoids such hazards as loss of precision or overflow because of the
  4408.      coercion. However, note that if w and d are unspecified and the number has
  4409.      no exact decimal representation, for example 1/3, some precision cutoff
  4410.      must be chosen by the implementation: only a finite number of digits may
  4411.      be printed.)
  4412.  
  4413.      If arg is a complex number or some non-numeric object, then it is printed
  4414.      using the format directive ~wD, thereby printing it in decimal radix and a
  4415.      minimum field width of w. (If it is desired to print each of the real part
  4416.      and imaginary part of a complex number using a ~E directive, then this
  4417.      must be done explicitly with two ~E directives and code to extract the two
  4418.      parts of the complex number.)
  4419.  
  4420.      [change_begin]
  4421.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4422.      binds *print-escape* to nil during the processing of the ~E directive.
  4423.      [change_end]
  4424.  
  4425.      (defun foo (x)
  4426.        (format nil
  4427.                "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E"
  4428.                x x x x))
  4429.      (foo 3.14159)  => "  3.14E+0| 31.42$-01|+.003E+03|  3.14E+0"
  4430.      (foo -3.14159) => " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0"
  4431.      (foo 1100.0)   => "  1.10E+3| 11.00$+02|+.001E+06|  1.10E+3"
  4432.      (foo 1100.0L0) => "  1.10L+3| 11.00$+02|+.001L+06|  1.10L+3"
  4433.      (foo 1.1E13)   => "*********| 11.00$+12|+.001E+16| 1.10E+13"
  4434.      (foo 1.1L120)  => "*********|??????????|%%%%%%%%%|1.10L+120"
  4435.      (foo 1.1L1200) => "*********|??????????|%%%%%%%%%|1.10L+1200"
  4436.  
  4437.      Here is an example of the effects of varying the scale factor:
  4438.  
  4439.      (dotimes (k 13)
  4440.        (format t " %Scale factor  2D: | 13,6,2,VE|"
  4441.                (- k 5) 3.14159))              ;Prints 13 lines
  4442.      Scale factor -5: | 0.000003E+06|
  4443.      Scale factor -4: | 0.000031E+05|
  4444.      Scale factor -3: | 0.000314E+04|
  4445.      Scale factor -2: | 0.003142E+03|
  4446.      Scale factor -1: | 0.031416E+02|
  4447.      Scale factor  0: | 0.314159E+01|
  4448.      Scale factor  1: | 3.141590E+00|
  4449.      Scale factor  2: | 31.41590E-01|
  4450.      Scale factor  3: | 314.1590E-02|
  4451.      Scale factor  4: | 3141.590E-03|
  4452.      Scale factor  5: | 31415.90E-04|
  4453.      Scale factor  6: | 314159.0E-05|
  4454.      Scale factor  7: | 3141590.E-06|
  4455.  
  4456. -------------------------------------------------------------------------------
  4457. Compatibility note: The ~E directive is similar to the Ew.d and Ew.dEe edit
  4458. descriptors in Fortran.
  4459.  
  4460. The presence or absence of the @ modifier corresponds to the effect of the
  4461. Fortran SS or SP edit descriptor; nothing in Common Lisp corresponds to the
  4462. Fortran S edit descriptor.
  4463.  
  4464. The scale factor specified by the parameter k corresponds to the scale factor k
  4465. specified by the Fortran kP edit descriptor; note, however, that the default
  4466. value for k is 1 in Common Lisp, as opposed to the default value of zero in
  4467. Fortran. (On the other hand, note that a scale factor of 1 is used for Fortran
  4468. list-directed output, which is roughly equivalent to using ~E with the w, d, e,
  4469. and overflowchar parameters omitted.)
  4470.  
  4471. In Common Lisp, the w and d parameters are optional; in Fortran, they are
  4472. required.
  4473.  
  4474. In Fortran, omitting e causes the exponent to be printed using either two or
  4475. three digits; if three digits are required, then the exponent marker is
  4476. omitted. In Common Lisp, omitting e causes the exponent to be printed using as
  4477. few digits as possible; the exponent marker is never omitted.
  4478.  
  4479. In Common Lisp, the pad character and overflow character are user-specifiable;
  4480. in Fortran they are always space and asterisk, respectively.
  4481.  
  4482. A Fortran implementation is prohibited from printing a representation of
  4483. negative zero; Common Lisp permits the printing of such a representation when
  4484. appropriate.
  4485.  
  4486. In MacLisp and Lisp Machine Lisp, the ~E format directive takes a single
  4487. parameter: the number of digits to use in the printed representation. This
  4488. incompatibility between Common Lisp and MacLisp was introduced for the sake of
  4489. cultural compatibility with Fortran.
  4490. -------------------------------------------------------------------------------
  4491.  
  4492. ~G   General floating-point. The next arg is printed as a floating-point number
  4493.      in either fixed-format or exponential notation as appropriate.
  4494.  
  4495.      The full form is ~w,d,e,k,overflowchar,padchar,exponentcharG. The format
  4496.      in which to print arg depends on the magnitude (absolute value) of the
  4497.      arg. Let n be an integer such that   . (If arg is zero, let n be 0.) Let
  4498.      ee equal e+2, or 4 if e is omitted. Let ww equal w-ee, or nil if w is
  4499.      omitted. If d is omitted, first let q be the number of digits needed to
  4500.      print arg with no loss of information and without leading or trailing
  4501.      zeros; then let d equal (max q (min n 7)). Let dd equal d-n.
  4502.  
  4503.      If 0ddd, then arg is printed as if by the format directives
  4504.  
  4505.      ~ww,dd,,overflowchar,padcharF~ee@T
  4506.  
  4507.      Note that the scale factor k is not passed to the ~F directive. For all
  4508.      other values of dd, arg is printed as if by the format directive
  4509.  
  4510.      ~w,d,e,k,overflowchar,padchar,exponentcharE
  4511.  
  4512.      In either case, an @ modifier is specified to the ~F or ~E directive if
  4513.      and only if one was specified to the ~G directive.
  4514.  
  4515.      [change_begin]
  4516.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4517.      binds *print-escape* to nil during the processing of the ~G directive.
  4518.      [change_end]
  4519.  
  4520.      [old_change_begin]
  4521.      Examples:
  4522.  
  4523.      (defun foo (x)
  4524.        (format nil
  4525.                "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G"
  4526.                x x x))
  4527.  
  4528.      (foo 0.0314159) => "  3.14E-2|314.2$-04|0.314E-01|  3.14E-2"
  4529.      (foo 0.314159)  => "  0.31   |0.314    |0.314    | 0.31    "
  4530.      (foo 3.14159)   => "   3.1   | 3.14    | 3.14    |  3.1    "
  4531.      (foo 31.4159)   => "   31.   | 31.4    | 31.4    |  31.    "
  4532.      (foo 314.159)   => "  3.14E+2| 314.    | 314.    |  3.14E+2"
  4533.      (foo 3141.59)   => "  3.14E+3|314.2$+01|0.314E+04|  3.14E+3"
  4534.      (foo 3141.59L0) => "  3.14L+3|314.2$+01|0.314L+04|  3.14L+3"
  4535.      (foo 3.14E12)   => "*********|314.0$+10|0.314E+13| 3.14E+12"
  4536.      (foo 3.14L120)  => "*********|?????????|%%%%%%%%%|3.14L+120"
  4537.      (foo 3.14L1200) => "*********|?????????|%%%%%%%%%|3.14L+1200"
  4538.  
  4539.      [old_change_end]
  4540.  
  4541.      [change_begin]
  4542.      Notice of correction. In the first edition, the example for the value
  4543.      3.14E12 contained two typographical errors:
  4544.  
  4545.      (foo 3.14E12)   => "*********|314.2$+10|0.314E+13| 3.14L+12"
  4546.                                        ^                    ^
  4547.                                        should be 0          should be E
  4548.  
  4549.      These have been corrected above.
  4550.      [change_end]
  4551.  
  4552. -------------------------------------------------------------------------------
  4553. Compatibility note: The ~G directive is similar to the Gw.d edit descriptor in
  4554. Fortran.
  4555.  
  4556. The Common Lisp rules for deciding between the use of ~F and ~E are compatible
  4557. with the rules used by Fortran but have been extended to cover the cases where
  4558. w or d is omitted or where e is specified.
  4559.  
  4560. In MacLisp and Lisp Machine Lisp, the ~G format directive is equivalent to the
  4561. Common Lisp ~@* directive. This incompatibility between Common Lisp and MacLisp
  4562. was introduced for the sake of cultural compatibility with Fortran.
  4563. -------------------------------------------------------------------------------
  4564.  
  4565. ~$   Dollars floating-point. The next arg is printed as a floating-point number
  4566.      in fixed-format notation. This format is particularly convenient for
  4567.      printing a value as dollars and cents.
  4568.  
  4569.      The full form is ~d,n,w,padchar$. The parameter d is the number of digits
  4570.      to print after the decimal point (default value 2); n is the minimum
  4571.      number of digits to print before the decimal point (default value 1); w is
  4572.      the minimum total width of the field to be printed (default value 0).
  4573.  
  4574.      First padding and the sign are output. If the arg is negative, then a
  4575.      minus sign is printed; if the arg is not negative, then a plus sign is
  4576.      printed if and only if the @ modifier was specified. If the : modifier is
  4577.      used, the sign appears before any padding, and otherwise after the
  4578.      padding. If w is specified and the number of other characters to be output
  4579.      is less than w, then copies of padchar (which defaults to a space) are
  4580.      output to make the total field width equal w. Then n digits are printed
  4581.      for the integer part of arg, with leading zeros if necessary; then a
  4582.      decimal point; then d digits of fraction, properly rounded.
  4583.  
  4584.      If the magnitude of arg is so large that more than m digits would have to
  4585.      be printed, where m is the larger of w and 100, then an implementation is
  4586.      free, at its discretion, to print the number using exponential notation
  4587.      instead, as if by the directive ~w,q,,,,padcharE, where w and padchar are
  4588.      present or omitted according to whether they were present or omitted in
  4589.      the ~$ directive, and where q=d+n-1, where d and n are the (possibly
  4590.      default) values given to the ~$ directive.
  4591.  
  4592.      If arg is a rational number, then it is coerced to be a single-float and
  4593.      then printed. (Alternatively, an implementation is permitted to process a
  4594.      rational number by any other method that has essentially the same behavior
  4595.      but avoids such hazards as loss of precision or overflow because of the
  4596.      coercion.)
  4597.  
  4598.      If arg is a complex number or some non-numeric object, then it is printed
  4599.      using the format directive ~wD, thereby printing it in decimal radix and a
  4600.      minimum field width of w. (If it is desired to print each of the real part
  4601.      and imaginary part of a complex number using a ~$ directive, then this
  4602.      must be done explicitly with two ~$ directives and code to extract the two
  4603.      parts of the complex number.)
  4604.  
  4605.      [change_begin]
  4606.      X3J13 voted in January 1989 (FORMAT-PRETTY-PRINT)   to specify that format
  4607.      binds *print-escape* to nil during the processing of the ~$ directive.
  4608.      [change_end]
  4609.  
  4610. ~%   This outputs a #\Newline character, thereby terminating the current output
  4611.      line and beginning a new one (see terpri).
  4612.  
  4613.      ~n% outputs n newlines.
  4614.  
  4615.      No arg is used. Simply putting a newline in the control string would work,
  4616.      but ~% is often used because it makes the control string look nicer in the
  4617.      middle of a Lisp program.
  4618.  
  4619. ~&   Unless it can be determined that the output stream is already at the
  4620.      beginning of a line, this outputs a newline (see fresh-line).
  4621.  
  4622.      ~n& calls fresh-line and then outputs n-1 newlines. ~0& does nothing.
  4623.  
  4624. ~|   This outputs a page separator character, if possible. ~n| does this n
  4625.      times. | is vertical bar, not capital I.
  4626.  
  4627. ~~   Tilde. This outputs a tilde. ~n~ outputs n tildes.
  4628.  
  4629. ~<newline>
  4630.      Tilde immediately followed by a newline ignores the newline and any
  4631.      following non-newline whitespace characters. With a :, the newline is
  4632.      ignored, but any following whitespace is left in place. With an @, the
  4633.      newline is left in place, but any following whitespace is ignored. This
  4634.      directive is typically used when a format control string is too long to
  4635.      fit nicely into one line of the program:
  4636.  
  4637.      (defun type-clash-error (fn nargs argnum right-type wrong-type)
  4638.        (format *error-output*
  4639.                "~&Function ~S requires its ~:[~:R~;~*~] ~
  4640.                 argument to be of type ~S,~%but it was called ~
  4641.                 with an argument of type ~S.~%"
  4642.                fn (eql nargs 1) argnum right-type wrong-type))
  4643.  
  4644.      (type-clash-error 'aref nil 2 'integer 'vector)  prints:
  4645.      Function AREF requires its second argument to be of type INTEGER,
  4646.      but it was called with an argument of type VECTOR.
  4647.  
  4648.      (type-clash-error 'car 1 1 'list 'short-float)  prints:
  4649.      Function CAR requires its argument to be of type LIST,
  4650.      but it was called with an argument of type SHORT-FLOAT.
  4651.  
  4652.      Note that in this example newlines appear in the output only as specified
  4653.      by the ~& and ~% directives; the actual newline characters in the control
  4654.      string are suppressed because each is preceded by a tilde.
  4655.  
  4656. ~T   Tabulate. This spaces over to a given column. ~colnum,colincT will output
  4657.      sufficient spaces to move the cursor to column colnum. If the cursor is
  4658.      already at or beyond column colnum, it will output spaces to move it to
  4659.      column colnum+k*colinc for the smallest positive integer k possible,
  4660.      unless colinc is zero, in which case no spaces are output if the cursor is
  4661.      already at or beyond column colnum. colnum and colinc default to 1.
  4662.  
  4663.      Ideally, the current column position is determined by examination of the
  4664.      destination, whether a stream or string. (Although no user-level operation
  4665.      for determining the column position of a stream is defined by Common Lisp,
  4666.      such a facility may exist at the implementation level.) If for some reason
  4667.      the current absolute column position cannot be determined by direct
  4668.      inquiry, format may be able to deduce the current column position by
  4669.      noting that certain directives (such as ~%, or ~&, or ~A with the argument
  4670.      being a string containing a newline) cause the column position to be reset
  4671.      to zero, and counting the number of characters emitted since that point.
  4672.      If that fails, format may attempt a similar deduction on the riskier
  4673.      assumption that the destination was at column zero when format was
  4674.      invoked. If even this heuristic fails or is implementationally
  4675.      inconvenient, at worst the ~T operation will simply output two spaces.
  4676.      (All this implies that code that uses format is more likely to be portable
  4677.      if all format control strings that use the ~T directive either begin with
  4678.      ~% or ~& to force a newline or are designed to be used only when the
  4679.      destination is known from other considerations to be at column zero.)
  4680.  
  4681.      ~@T performs relative tabulation. ~colrel,colinc@T outputs colrel spaces
  4682.      and then outputs the smallest non-negative number of additional spaces
  4683.      necessary to move the cursor to a column that is a multiple of colinc. For
  4684.      example, the directive ~3,8@T outputs three spaces and then moves the
  4685.      cursor to a ``standard multiple-of-eight tab stop'' if not at one already.
  4686.      If the current output column cannot be determined, however, then colinc is
  4687.      ignored, and exactly colrel spaces are output.
  4688.  
  4689.      [change_begin]
  4690.      X3J13 voted in June 1989 (PRETTY-PRINT-INTERFACE)   to define ~:T and ~:@T
  4691.      to perform tabulation relative to a point defined by the pretty printing
  4692.      process (see section 27.4).
  4693.      [change_end]
  4694.  
  4695. ~*   The next arg is ignored. ~n* ignores the next n arguments.
  4696.  
  4697.      ~:* ``ignores backwards''; that is, it backs up in the list of arguments
  4698.      so that the argument last processed will be processed again. ~n:* backs up
  4699.      n arguments.
  4700.  
  4701.      When within a ~{ construct (see below), the ignoring (in either direction)
  4702.      is relative to the list of arguments being processed by the iteration.
  4703.  
  4704.      ~n@* is an ``absolute goto'' rather than a ``relative goto'': it goes to
  4705.      the nth arg, where 0 means the first one; n defaults to 0, so ~@* goes
  4706.      back to the first arg. Directives after a ~n@* will take arguments in
  4707.      sequence beginning with the one gone to. When within a ~{ construct, the
  4708.      ``goto'' is relative to the list of arguments being processed by the
  4709.      iteration.
  4710.  
  4711. ~?   Indirection. The next arg must be a string, and the one after it a list;
  4712.      both are consumed by the ~? directive. The string is processed as a format
  4713.      control string, with the elements of the list as the arguments. Once the
  4714.      recursive processing of the control string has been finished, then
  4715.      processing of the control string containing the ~? directive is resumed.
  4716.      Example:
  4717.  
  4718.      (format nil "~? ~D" "<~A ~D>" '("Foo" 5) 7) => "<Foo 5> 7"
  4719.      (format nil "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) => "<Foo 5> 7"
  4720.  
  4721.      Note that in the second example three arguments are supplied to the
  4722.      control string "<~A ~D>", but only two are processed and the third is
  4723.      therefore ignored.
  4724.  
  4725.      With the @ modifier, only one arg is directly consumed. The arg must be a
  4726.      string; it is processed as part of the control string as if it had
  4727.      appeared in place of the ~@? construct, and any directives in the
  4728.      recursively processed control string may consume arguments of the control
  4729.      string containing the ~@? directive. Example:
  4730.  
  4731.      (format nil "~@? ~D" "<~A ~D>" "Foo" 5 7) => "<Foo 5> 7"
  4732.      (format nil "~@? ~D" "<~A ~D>" "Foo" 5 14 7) => "<Foo 5> 14"
  4733.  
  4734.      Here is a rather sophisticated example. The format function itself, as
  4735.      implemented at one time in Lisp Machine Lisp, used a routine internal to
  4736.      the format package called format-error to signal error messages;
  4737.      format-error in turn used error, which used format recursively. Now
  4738.      format-error took a string and arguments, just like format, but also
  4739.      printed the control string to format (which at this point was available in
  4740.      the global variable *ctl-string*) and a little arrow showing where in the
  4741.      processing of the control string the error occurred. The variable
  4742.      *ctl-index* pointed one character after the place of the error.
  4743.  
  4744.      (defun format-error (string &rest args)     ;Example
  4745.        (error nil "~?~%~V@T  ~%~3@T "~A "~%"
  4746.               string args (+ *ctl-index* 3) *ctl-string*))
  4747.  
  4748.      (The character set used in the Lisp Machine Lisp implementation contains a
  4749.      down-arrow character   , which is not a standard Common Lisp character.)
  4750.      This first processed the given string and arguments using ~?, then output
  4751.      a newline, tabbed a variable amount for printing the down-arrow, and
  4752.      printed the control string between double quotes (note the use of " to
  4753.      include double quotes within the control string). The effect was something
  4754.      like this:
  4755.  
  4756.      (format t "The item is a ~[Foo~;Bar~;Loser~]." 'quux)
  4757.      >>ERROR: The argument to the FORMAT "~[" command
  4758.               must be a number.
  4759.  
  4760.         "The item is a ~[Foo~;Bar~;Loser~]."
  4761.  
  4762. -------------------------------------------------------------------------------
  4763. Implementation note: Implementors may wish to report errors occurring within
  4764. format control strings in the manner outlined here. It looks pretty flashy when
  4765. done properly.
  4766. -------------------------------------------------------------------------------
  4767.  
  4768. [change_begin]
  4769. X3J13 voted in June 1989 (PRETTY-PRINT-INTERFACE)   to introduce certain format
  4770. directives to support the user interface to the pretty printer described in
  4771. detail in chapter 27.
  4772.  
  4773. ~_   Conditional newline. Without any modifiers, the directive ~_ is equivalent
  4774.      to (pprint-newline :linear). The directive ~@_ is equivalent to
  4775.      (pprint-newline :miser). The directive ~:_ is equivalent to
  4776.      (pprint-newline :fill). The directive ~:@_ is equivalent to
  4777.      (pprint-newline :mandatory).
  4778.  
  4779. ~W   Write. An arg, any Lisp object, is printed obeying every printer control
  4780.      variable (as by write). See section 27.4 for details.
  4781.  
  4782. ~I   Indent. The directive ~nI is equivalent to (pprint-indent :block n). The
  4783.      directive ~:nI is equivalent to (pprint-indent :current n). In both cases,
  4784.      n defaults to zero, if it is omitted.
  4785.  
  4786. [change_end]
  4787.  
  4788. The format directives after this point are much more complicated than the
  4789. foregoing; they constitute control structures that can perform case conversion,
  4790. conditional selection, iteration, justification, and non-local exits. Used with
  4791. restraint, they can perform powerful tasks. Used with abandon, they can produce
  4792. completely unreadable and unmaintainable code.
  4793.  
  4794. The case-conversion, conditional, iteration, and justification constructs can
  4795. contain other formatting constructs by bracketing them. These constructs must
  4796. nest properly with respect to each other. For example, it is not legitimate to
  4797. put the start of a case-conversion construct in each arm of a conditional and
  4798. the end of the case-conversion construct outside the conditional:
  4799.  
  4800. (format nil "~:[abc~:@(def~;ghi~:@(jkl~]mno~)" x)  ;Illegal!
  4801.  
  4802. One might expect this to produce either "abcDEFMNO" or "ghiJKLMNO", depending
  4803. on whether x is false or true; but in fact the construction is illegal because
  4804. the ~[...~;...~] and ~(...~) constructs are not properly nested.
  4805.  
  4806. The processing indirection caused by the ~? directive is also a kind of nesting
  4807. for the purposes of this rule of proper nesting. It is not permitted to start a
  4808. bracketing construct within a string processed under control of a ~? directive
  4809. and end the construct at some point after the ~? construct in the string
  4810. containing that construct, or vice versa. For example, this situation is
  4811. illegal:
  4812.  
  4813. (format nil "~?ghi~)" "abc~@(def")     ;Illegal!
  4814.  
  4815. One might expect it to produce "abcDEFGHI", but in fact the construction is
  4816. illegal because the ~? and ~(...~) constructs are not properly nested.
  4817.  
  4818. ~(str~)
  4819.      Case conversion. The contained control string str is processed, and what
  4820.      it produces is subject to case conversion: ~( converts every uppercase
  4821.      character to the corresponding lowercase character; ~:( capitalizes all
  4822.      words, as if by string-capitalize; ~@( capitalizes just the first word and
  4823.      forces the rest to lowercase; ~:@( converts every lowercase character to
  4824.      the corresponding uppercase character. In this example, ~@( is used to
  4825.      cause the first word produced by ~@R to be capitalized:
  4826.  
  4827.      (format nil "~@R ~(~@R~)" 14 14) => "XIV xiv"
  4828.      (defun f (n) (format nil "~@(~R~) error~:P detected." n))
  4829.      (f 0) => "Zero errors detected."
  4830.      (f 1) => "One error detected."
  4831.      (f 23) => "Twenty-three errors detected."
  4832.  
  4833. ~[str0~;str1~;...~;strn~]
  4834.      Conditional expression. This is a set of control strings, called clauses,
  4835.      one of which is chosen and used. The clauses are separated by ~; and the
  4836.      construct is terminated by ~]. For example,
  4837.  
  4838.      "~[Siamese~;Manx~;Persian~] Cat"
  4839.  
  4840.      The argth clause is selected, where the first clause is number 0. If a
  4841.      prefix parameter is given (as ~n[), then the parameter is used instead of
  4842.      an argument. (This is useful only if the parameter is specified by #, to
  4843.      dispatch on the number of arguments remaining to be processed.) If arg is
  4844.      out of range, then no clause is selected (and no error is signaled). After
  4845.      the selected alternative has been processed, the control string continues
  4846.      after the ~].
  4847.  
  4848.      ~[str0~;str1~;...~;strn~:;default~] has a default case. If the last ~;
  4849.      used to separate clauses is ~:; instead, then the last clause is an
  4850.      ``else'' clause that is performed if no other clause is selected. For
  4851.      example:
  4852.  
  4853.      "~[Siamese~;Manx~;Persian~:;Alley~] Cat"
  4854.  
  4855.      ~:[false~;true~] selects the false control string if arg is nil, and
  4856.      selects the true control string otherwise.
  4857.  
  4858.      ~@[true~] tests the argument. If it is not nil, then the argument is not
  4859.      used up by the ~@[ command but remains as the next one to be processed,
  4860.      and the one clause true is processed. If the arg is nil, then the argument
  4861.      is used up, and the clause is not processed. The clause therefore should
  4862.      normally use exactly one argument, and may expect it to be non-nil. For
  4863.      example:
  4864.  
  4865.      (setq *print-level* nil *print-length* 5)
  4866.      (format nil "~@[ print level = ~D~]~@[ print length = ~D~]"
  4867.                  *print-level* *print-length*)
  4868.         =>  " print length = 5"
  4869.  
  4870.      The combination of ~[ and # is useful, for example, for dealing with
  4871.      English conventions for printing lists:
  4872.  
  4873.      (setq foo "Items:~#[ none~; ~S~; ~S and ~S~
  4874.                 ~:;~@{~#[~; and~]
  4875.      ~S~^,~}~].")
  4876.      (format nil foo)
  4877.              =>  "Items: none."
  4878.      (format nil foo 'foo)
  4879.              =>  "Items: FOO."
  4880.      (format nil foo 'foo 'bar)
  4881.              =>  "Items: FOO and BAR."
  4882.      (format nil foo 'foo 'bar 'baz)
  4883.              =>  "Items: FOO, BAR, and BAZ."
  4884.      (format nil foo 'foo 'bar 'baz 'quux)
  4885.              =>  "Items: FOO, BAR, BAZ, and QUUX."
  4886.  
  4887. ~;   This separates clauses in ~[ and ~< constructions. It is an error
  4888.      elsewhere.
  4889.  
  4890. ~]   This terminates a ~[. It is an error elsewhere.
  4891.  
  4892. ~{str~}
  4893.      Iteration. This is an iteration construct. The argument should be a list,
  4894.      which is used as a set of arguments as if for a recursive call to format.
  4895.      The string str is used repeatedly as the control string. Each iteration
  4896.      can absorb as many elements of the list as it likes as arguments; if str
  4897.      uses up two arguments by itself, then two elements of the list will get
  4898.      used up each time around the loop. If before any iteration step the list
  4899.      is empty, then the iteration is terminated. Also, if a prefix parameter n
  4900.      is given, then there will be at most n repetitions of processing of str.
  4901.      Finally, the ~^ directive can be used to terminate the iteration
  4902.      prematurely.
  4903.  
  4904.      Here are some simple examples:
  4905.  
  4906.      (format nil
  4907.              "The winners are:~{ ~S~}."
  4908.              '(fred harry jill))
  4909.           => "The winners are: FRED HARRY JILL."
  4910.  
  4911.      (format nil "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3))
  4912.           => "Pairs: <A,1> <B,2> <C,3>."
  4913.  
  4914.      ~:{str~} is similar, but the argument should be a list of sublists. At
  4915.      each repetition step, one sublist is used as the set of arguments for
  4916.      processing str; on the next repetition, a new sublist is used, whether or
  4917.      not all of the last sublist had been processed. Example:
  4918.  
  4919.      (format nil "Pairs:~:{ <~S,~S>~}."
  4920.                  '((a 1) (b 2) (c 3)))
  4921.           => "Pairs: <A,1> <B,2> <C,3>."
  4922.  
  4923.      ~@{str~} is similar to ~{str~}, but instead of using one argument that is
  4924.      a list, all the remaining arguments are used as the list of arguments for
  4925.      the iteration. Example:
  4926.  
  4927.      (format nil "Pairs:~@{ <~S,~S>~}."
  4928.                  'a 1 'b 2 'c 3)
  4929.           => "Pairs: <A,1> <B,2> <C,3>."
  4930.  
  4931.      If the iteration is terminated before all the remaining arguments are
  4932.      consumed, then any arguments not processed by the iteration remain to be
  4933.      processed by any directives following the iteration construct.
  4934.  
  4935.      ~:@{str~} combines the features of ~:{str~} and ~@{str~}. All the
  4936.      remaining arguments are used, and each one must be a list. On each
  4937.      iteration, the next argument is used as a list of arguments to str.
  4938.      Example:
  4939.  
  4940.      (format nil "Pairs:~:@{ <~S,~S>~}."
  4941.                  '(a 1) '(b 2) '(c 3))
  4942.           => "Pairs: <A,1> <B,2> <C,3>."
  4943.  
  4944.      Terminating the repetition construct with ~:} instead of ~} forces str to
  4945.      be processed at least once, even if the initial list of arguments is null
  4946.      (however, it will not override an explicit prefix parameter of zero).
  4947.  
  4948.      If str is empty, then an argument is used as str. It must be a string and
  4949.      precede any arguments processed by the iteration. As an example, the
  4950.      following are equivalent:
  4951.  
  4952.      (apply #'format stream string arguments)
  4953.      (format stream "~1{~:}" string arguments)
  4954.  
  4955.      This will use string as a formatting string. The ~1{ says it will be
  4956.      processed at most once, and the ~:} says it will be processed at least
  4957.      once. Therefore it is processed exactly once, using arguments as the
  4958.      arguments. This case may be handled more clearly by the ~? directive, but
  4959.      this general feature of ~{ is more powerful than ~?.
  4960.  
  4961. ~}   This terminates a ~{. It is an error elsewhere.
  4962.  
  4963. ~mincol,colinc,minpad,padchar<str~>
  4964.      Justification. This justifies the text produced by processing str within a
  4965.      field at least mincol columns wide. str may be divided up into segments
  4966.      with ~;, in which case the spacing is evenly divided between the text
  4967.      segments.
  4968.  
  4969.      With no modifiers, the leftmost text segment is left-justified in the
  4970.      field, and the rightmost text segment right-justified; if there is only
  4971.      one text element, as a special case, it is right-justified. The : modifier
  4972.      causes spacing to be introduced before the first text segment; the @
  4973.      modifier causes spacing to be added after the last. The minpad parameter
  4974.      (default 0) is the minimum number of padding characters to be output
  4975.      between each segment. The padding character is specified by padchar, which
  4976.      defaults to the space character. If the total width needed to satisfy
  4977.      these constraints is greater than mincol, then the width used is
  4978.      mincol+k*colinc for the smallest possible non-negative integer value k;
  4979.      colinc defaults to 1, and mincol defaults to 0.
  4980.  
  4981.      (format nil "~10<foo~;bar~>")          =>  "foo    bar"
  4982.      (format nil "~10:<foo~;bar~>")         =>  "  foo  bar"
  4983.      (format nil "~10:@<foo~;bar~>")        =>  "  foo bar "
  4984.      (format nil "~10<foobar~>")            =>  "    foobar"
  4985.      (format nil "~10:<foobar~>")           =>  "    foobar"
  4986.      (format nil "~10@<foobar~>")           =>  "foobar    "
  4987.      (format nil "~10:@<foobar~>")          =>  "  foobar  "
  4988.  
  4989.      Note that str may include format directives. All the clauses in str are
  4990.      processed in order; it is the resulting pieces of text that are justified.
  4991.  
  4992.      The ~^ directive may be used to terminate processing of the clauses
  4993.      prematurely, in which case only the completely processed clauses are
  4994.      justified.
  4995.  
  4996.      If the first clause of a ~< is terminated with ~:; instead of ~;, then it
  4997.      is used in a special way. All of the clauses are processed (subject to ~^,
  4998.      of course), but the first one is not used in performing the spacing and
  4999.      padding. When the padded result has been determined, then if it will fit
  5000.      on the current line of output, it is output, and the text for the first
  5001.      clause is discarded. If, however, the padded text will not fit on the
  5002.      current line, then the text segment for the first clause is output before
  5003.      the padded text. The first clause ought to contain a newline (such as a ~%
  5004.      directive). The first clause is always processed, and so any arguments it
  5005.      refers to will be used; the decision is whether to use the resulting
  5006.      segment of text, not whether to process the first clause. If the ~:; has a
  5007.      prefix parameter n, then the padded text must fit on the current line with
  5008.      n character positions to spare to avoid outputting the first clause's
  5009.      text. For example, the control string
  5010.  
  5011.      "~%;; ~{~<~%;; ~1:; ~S~>~^,~}.~%"
  5012.  
  5013.      can be used to print a list of items separated by commas without breaking
  5014.      items over line boundaries, beginning each line with ;; . The prefix
  5015.      parameter 1 in ~1:; accounts for the width of the comma that will follow
  5016.      the justified item if it is not the last element in the list, or the
  5017.      period if it is. If ~:; has a second prefix parameter, then it is used as
  5018.      the width of the line, thus overriding the natural line width of the
  5019.      output stream. To make the preceding example use a line width of 50, one
  5020.      would write
  5021.  
  5022.      "~%;; ~{~<~%;; ~1,50:; ~S~>~^,~}.~%"
  5023.  
  5024.      If the second argument is not specified, then format uses the line width
  5025.      of the output stream. If this cannot be determined (for example, when
  5026.      producing a string result), then format uses 72 as the line length.
  5027.  
  5028. ~>   Terminates a ~<. It is an error elsewhere.
  5029.  
  5030.      [change_begin]
  5031.      X3J13 voted in June 1989 (PRETTY-PRINT-INTERFACE)   to introduce certain
  5032.      format directives to support the user interface to the pretty printer. If
  5033.      ~:> is used to terminate a ~<... directive, the directive is equivalent to
  5034.      a call on pprint-logical-block. See section 27.4 for details.
  5035.      [change_end]
  5036.  
  5037. ~^   Up and out. This is an escape construct. If there are no more arguments
  5038.      remaining to be processed, then the immediately enclosing ~{ or ~<
  5039.      construct is terminated. If there is no such enclosing construct, then the
  5040.      entire formatting operation is terminated. In the ~< case, the formatting
  5041.      is performed, but no more segments are processed before doing the
  5042.      justification. The ~^ should appear only at the beginning of a ~< clause,
  5043.      because it aborts the entire clause it appears in (as well as all
  5044.      following clauses). ~^ may appear anywhere in a ~{ construct.
  5045.  
  5046.      (setq donestr "Done.~^  ~D warning~:P.~^  ~D error~:P.")
  5047.      (format nil donestr) => "Done."
  5048.      (format nil donestr 3) => "Done.  3 warnings."
  5049.      (format nil donestr 1 5) => "Done.  1 warning.  5 errors."
  5050.  
  5051.      If a prefix parameter is given, then termination occurs if the parameter
  5052.      is zero. (Hence ~^ is equivalent to ~#^.) If two parameters are given,
  5053.      termination occurs if they are equal. If three parameters are given,
  5054.      termination occurs if the first is less than or equal to the second and
  5055.      the second is less than or equal to the third. Of course, this is useless
  5056.      if all the prefix parameters are constants; at least one of them should be
  5057.      a # or a V parameter.
  5058.  
  5059.      If ~^ is used within a ~:{ construct, then it merely terminates the
  5060.      current iteration step (because in the standard case it tests for
  5061.      remaining arguments of the current step only); the next iteration step
  5062.      commences immediately. To terminate the entire iteration process, use ~:^.
  5063.  
  5064.      [change_begin]
  5065.      X3J13 voted in March 1988 (FORMAT-COLON-UPARROW-SCOPE)   to clarify the
  5066.      behavior of ~:^ as follows. It may be used only if the command it would
  5067.      terminate is ~:{ or ~:@{. The entire iteration process is terminated if
  5068.      and only if the sublist that is supplying the arguments for the current
  5069.      iteration step is the last sublist (in the case of terminating a ~:{
  5070.      command) or the last argument to that call to format (in the case of
  5071.      terminating a ~:@{ command). Note furthermore that while ~^ is equivalent
  5072.      to ~#^ in all circumstances, ~:^ is not equivalent to ~:#^ because the
  5073.      latter terminates the entire iteration if and only if no arguments remain
  5074.      for the current iteration step (as opposed to no arguments remaining for
  5075.      the entire iteration process).
  5076.  
  5077.      Here are some examples of the differences in the behaviors of ~^, ~:^, and
  5078.      ~:#^.
  5079.  
  5080.      (format nil
  5081.              "~:{/~S~^ ...~}"
  5082.              '((hot dog) (hamburger) (ice cream) (french fries)))
  5083.       => "/HOT .../HAMBURGER/ICE .../FRENCH ..."
  5084.  
  5085.      For each sublist, `` ...'' appears after the first word unless there are
  5086.      no additional words.
  5087.  
  5088.      (format nil
  5089.              "~:{/~S~:^ ...~}"
  5090.              '((hot dog) (hamburger) (ice cream) (french fries)))
  5091.       => "/HOT .../HAMBURGER .../ICE .../FRENCH"
  5092.  
  5093.      For each sublist, `` ...'' always appears after the first word, unless it
  5094.      is the last sublist, in which case the entire iteration is terminated.
  5095.  
  5096.      (format nil
  5097.              "~:{/~S~:#^ ...~}"
  5098.              '((hot dog) (hamburger) (ice cream) (french fries)))
  5099.       => "/HOT .../HAMBURGER"
  5100.  
  5101.      For each sublist, `` ...'' appears after the first word, but if the
  5102.      sublist has only one word then the entire iteration is terminated.
  5103.      [change_end]
  5104.  
  5105.      If ~^ appears within a control string being processed under the control of
  5106.      a ~? directive, but not within any ~{ or ~< construct within that string,
  5107.      then the string being processed will be terminated, thereby ending
  5108.      processing of the ~? directive. Processing then continues within the
  5109.      string containing the ~? directive at the point following that directive.
  5110.  
  5111.      If ~^ appears within a ~[ or ~( construct, then all the commands up to the
  5112.      ~^ are properly selected or case-converted, the ~[ or ~( processing is
  5113.      terminated, and the outward search continues for a ~{ or ~< construct to
  5114.      be terminated. For example:
  5115.  
  5116.      (setq tellstr "~@(~@[~R~]~^ ~A.~)")
  5117.      (format nil tellstr 23) => "Twenty-three."
  5118.      (format nil tellstr nil "losers") => "Losers."
  5119.      (format nil tellstr 23 "losers") => "Twenty-three losers."
  5120.  
  5121.      Here are some examples of the use of ~^ within a ~< construct.
  5122.  
  5123.      (format nil "~15<~S~;~^~S~;~^~S~>" 'foo)
  5124.              =>  "            FOO"
  5125.      (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar)
  5126.              =>  "FOO         BAR"
  5127.      (format nil "~15<~S~;~^~S~;~^~S~>" 'foo 'bar 'baz)
  5128.              =>  "FOO   BAR   BAZ"
  5129.  
  5130. [old_change_begin]
  5131. -------------------------------------------------------------------------------
  5132. Compatibility note: The ~Q directive and user-defined directives of Zetalisp
  5133. have been omitted here, as well as control lists (as opposed to strings), which
  5134. are rumored to be changing in meaning.
  5135. -------------------------------------------------------------------------------
  5136.  
  5137. [old_change_end]
  5138.  
  5139. [change_begin]
  5140. X3J13 voted in June 1989 (PRETTY-PRINT-INTERFACE)   to introduce user-defined
  5141. directives in the form of the ~/.../ directive. See section 27.4 for details.
  5142.  
  5143. The hairiest format control string I have ever seen in shown in table 22-8. It
  5144. started innocently enough as part of the simulator for Connection Machine Lisp
  5145. [44,57]; the xapping data type, defined by defstruct, needed a :print-function
  5146. option so that xappings would print properly. As this data type became more
  5147. complicated, step by step, so did the format control string.
  5148.  
  5149.  
  5150.  
  5151. ----------------------------------------------------------------
  5152. Table 22-8: Print Function for the Xapping Data Type
  5153.  
  5154. (defun print-xapping (xapping stream depth)
  5155.   (declare (ignore depth))
  5156.   (format stream
  5157.           ;; Are you ready for this one?
  5158.           "~:[{~;[~]~:{~S~:[->~S~;~*~]~:^ ~}~:[~; ~]~
  5159.            ~{~S->~^ ~}~:[~; ~]~[~*~;->~S~;->~*~]~:[}~;]~]"
  5160.           ;; Is that clear?
  5161.           (xectorp xapping)
  5162.           (do ((vp (xectorp xapping))
  5163.                (sp (finite-part-is-xetp xapping))
  5164.                (d (xapping-domain xapping) (cdr d))
  5165.                (r (xapping-range xapping) (cdr r))
  5166.                (z '() (cons (list (if vp (car r) (car d))
  5167.                                   (or vp sp)
  5168.                                   (car r))
  5169.                             z)))
  5170.               ((null d) (reverse z)))
  5171.           (and (xapping-domain xapping)
  5172.                (or (xapping-exceptions xapping)
  5173.                    (xapping-infinite xapping)))
  5174.           (xapping-exceptions xapping)
  5175.           (and (xapping-exceptions xapping)
  5176.                (xapping-infinite xapping))
  5177.           (ecase (xapping-infinite xapping)
  5178.             ((nil) 0)
  5179.             (:constant 1)
  5180.             (:universal 2))
  5181.           (xapping-default xapping)
  5182.           (xectorp xapping)))
  5183.  
  5184. See section 22.1.5 for the defstruct definition of the xapping data
  5185. type, whose accessor functions are used in this code.
  5186. ----------------------------------------------------------------
  5187.  
  5188. See the description of set-macro-character for a discussion of xappings and the
  5189. defstruct definition. Assume that the predicate xectorp is true of a xapping if
  5190. it is a xector, and that the predicate finite-part-is-xetp is true if every
  5191. value in the range is the same as its corresponding index.
  5192.  
  5193. Here is a blow-by-blow description of the parts of this format string:
  5194.  
  5195. ~:[{~;[~]                  Print ``['' for a xector, and ``{'' otherwise.
  5196.  
  5197. ~:{~S~:[->~S~;~*~]~:^ ~}   Given a list of lists, print the pairs.
  5198.                            Each sublist has three elements: the index
  5199.                            (or the value if we're printing a xector);
  5200.                            a flag that is true for either a xector or
  5201.                            xet (in which case no arrow is printed);
  5202.                            and the value.  Note the use of ~:{ to
  5203.                            iterate, and the use of ~:^ to avoid
  5204.                            printing a separating space after the final
  5205.                            pair (or at all, if there are no pairs).
  5206.  
  5207. ~:[~; ~]                   If there were pairs and there are
  5208.                            exceptions or an infinite part, print a
  5209.                            separating space.
  5210.  
  5211. ~                 Do nothing.  This merely allows the format
  5212.                            control string to be broken across two lines.
  5213.  
  5214. ~{~S->~^ ~}                Given a list of exception indices, print them.
  5215.                            Note the use of ~{ to iterate, and the use
  5216.                            of ~^ to avoid printing a separating space
  5217.                            after the final exception (or at all, if
  5218.                            there are no exceptions).
  5219.  
  5220. ~:[~; ~]                   If there were exceptions and there is an
  5221.                            infinite part, print a separating space.
  5222.  
  5223. ~[~*~;->~S~;->~*~]         Use ~[ to choose one of three cases for
  5224.                            printing the infinite part.
  5225.  
  5226. ~:[}~;]~]                  Print ``]'' for a xector, and ``}'' otherwise.
  5227.  
  5228. [change_end]
  5229.  
  5230. -------------------------------------------------------------------------------
  5231.  
  5232. 22.4. Querying the User
  5233.  
  5234. The following functions provide a convenient and consistent interface for
  5235. asking questions of the user. Questions are printed and the answers are read
  5236. using the stream *query-io*, which normally is synonymous with *terminal-io*
  5237. but can be rebound to another stream for special applications.
  5238.  
  5239. [Function]
  5240. y-or-n-p &optional format-string &rest arguments
  5241.  
  5242. This predicate is for asking the user a question whose answer is either ``yes''
  5243. or ``no.'' It types out a message (if supplied), reads an answer in some
  5244. implementation-dependent manner (intended to be short and simple, like reading
  5245. a single character such as Y or N), and is true if the answer was ``yes'' or
  5246. false if the answer was ``no.''
  5247.  
  5248. If the format-string argument is supplied and not nil, then a fresh-line
  5249. operation is performed; then a message is printed as if the format-string and
  5250. arguments were given to format. Otherwise it is assumed that any message has
  5251. already been printed by other means. If you want a question mark at the end of
  5252. the message, you must put it there yourself; y-or-n-p will not add it. However,
  5253. the message should not contain an explanatory note such as (Y or N), because
  5254. the nature of the interface provided for y-or-n-p by a given implementation
  5255. might not involve typing a character on a keyboard; y-or-n-p will provide such
  5256. a note if appropriate.
  5257.  
  5258. All input and output are performed using the stream in the global variable
  5259. *query-io*.
  5260.  
  5261. Here are some examples of the use of y-or-n-p:
  5262.  
  5263. (y-or-n-p "Produce listing file?")
  5264. (y-or-n-p "Cannot connect to network host ~S.  Retry?" host)
  5265.  
  5266. y-or-n-p should only be used for questions that the user knows are coming or in
  5267. situations where the user is known to be waiting for a response of some kind.
  5268. If the user is unlikely to anticipate the question, or if the consequences of
  5269. the answer might be grave and irreparable, then y-or-n-p should not be used
  5270. because the user might type ahead and thereby accidentally answer the question.
  5271. For such questions as ``Shall I delete all of your files?'' it is better to use
  5272. yes-or-no-p.
  5273.  
  5274. [Function]
  5275. yes-or-no-p &optional format-string &rest arguments
  5276.  
  5277. This predicate, like y-or-n-p, is for asking the user a question whose answer
  5278. is either ``yes'' or ``no.'' It types out a message (if supplied), attracts the
  5279. user's attention (for example, by ringing the terminal's bell), and reads a
  5280. reply in some implementation-dependent manner. It is intended that the reply
  5281. require the user to take more action than just a single keystroke, such as
  5282. typing the full word yes or no followed by a newline.
  5283.  
  5284. If the format-string argument is supplied and not nil, then a fresh-line
  5285. operation is performed; then a message is printed as if the format-string and
  5286. arguments were given to format. Otherwise it is assumed that any message has
  5287. already been printed by other means. If you want a question mark at the end of
  5288. the message, you must put it there yourself; yes-or-no-p will not add it.
  5289. However, the message should not contain an explanatory note such as (Yes or No)
  5290. because the nature of the interface provided for yes-or-no-p by a given
  5291. implementation might not involve typing the reply on a keyboard; yes-or-no-p
  5292. will provide such a note if appropriate.
  5293.  
  5294. All input and output are performed using the stream in the global variable
  5295. *query-io*.
  5296.  
  5297. To allow the user to answer a yes-or-no question with a single character, use
  5298. y-or-n-p. yes-or-no-p should be used for unanticipated or momentous questions;
  5299. this is why it attracts attention and why it requires a multiple-action
  5300. sequence to answer it.
  5301.  
  5302. -------------------------------------------------------------------------------
  5303.  
  5304.  
  5305.  
  5306.